Skip to content

Commit 1503fa6

Browse files
committed
minor optim: OAuthParameterSet ArrayList size
1 parent 28fe56b commit 1503fa6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

api/src/main/java/org/asynchttpclient/oauth/OAuthSignatureCalculator.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ else if (scheme.equals("https"))
122122
* List of all query and form parameters added to this request; needed
123123
* for calculating request signature
124124
*/
125-
OAuthParameterSet allParameters = new OAuthParameterSet();
125+
int allParametersSize = 5
126+
+ (userAuth.getKey() != null ? 1 : 0)
127+
+ (formParams != null ? formParams.size() : 0)
128+
+ (queryParams != null ? queryParams.size() : 0);
129+
OAuthParameterSet allParameters = new OAuthParameterSet(allParametersSize);
126130

127131
// start with standard OAuth parameters we need
128132
allParameters.add(KEY_OAUTH_CONSUMER_KEY, consumerAuth.getKey());
@@ -203,9 +207,10 @@ protected long generateTimestamp() {
203207
* when it would occur it'd be harder to track down.
204208
*/
205209
final static class OAuthParameterSet {
206-
final private ArrayList<Parameter> allParameters = new ArrayList<>();
210+
private final ArrayList<Parameter> allParameters;
207211

208-
public OAuthParameterSet() {
212+
public OAuthParameterSet(int size) {
213+
allParameters = new ArrayList<>(size);
209214
}
210215

211216
public OAuthParameterSet add(String key, String value) {

0 commit comments

Comments
 (0)