Skip to content

Commit 3c08288

Browse files
committed
Optimize HashSet Initialization
Noticed this while debugging - we can avoid wasting memory/cpu creating 16 buckets when we only need one or a few.
1 parent 3c664d1 commit 3c08288

File tree

1 file changed

+2
-2
lines changed
  • modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson

1 file changed

+2
-2
lines changed

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
322322

323323
static {
324324
// a set of all properties/fields (JSON key names)
325-
openapiFields = new HashSet<String>();
325+
openapiFields = new HashSet<String>({{#allVars}}1{{^-last}} + {{/-last}}{{/allVars}}{{^allVars}}0{{/allVars}});
326326
{{#allVars}}
327327
openapiFields.add("{{baseName}}");
328328
{{/allVars}}
329329

330330
// a set of required properties/fields (JSON key names)
331-
openapiRequiredFields = new HashSet<String>();
331+
openapiRequiredFields = new HashSet<String>({{#requiredVars}}1{{^-last}} + {{/-last}}{{/requiredVars}}{{^requiredVars}}0{{/requiredVars}});
332332
{{#requiredVars}}
333333
openapiRequiredFields.add("{{baseName}}");
334334
{{/requiredVars}}

0 commit comments

Comments
 (0)