Share Integer.MAX_VALUE 95/29095/2
authorRobert Varga <rovarga@cisco.com>
Sun, 1 Nov 2015 13:54:35 +0000 (14:54 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 2 Nov 2015 08:19:03 +0000 (08:19 +0000)
As it turns out Integer.MAX_VALUE is not usually cached for boxing. Add
an explicit cache to eliminate ~160K Integers wasting 2.5MB on a simple
SchemaContext.

Change-Id: I47b5b00358d5726eddc8baf675bda1f850823362
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveConstraintDefinitionImpl.java

index 1c4032cebc5bbf3142c8d1fcd3fe836d0936b422..a91f518ab0ac5a5a888aabdadc821825a2f2b23d 100644 (file)
@@ -16,6 +16,8 @@ import org.opendaylight.yangtools.yang.model.api.MustDefinition;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 
 public final class EffectiveConstraintDefinitionImpl implements ConstraintDefinition {
+    private static final Integer UNBOUNDED_INT = Integer.MAX_VALUE;
+    private static final String UNBOUNDED_STR = "unbounded";
     private final RevisionAwareXPath whenCondition;
     private final Set<MustDefinition> mustConstraints;
     private final Boolean mandatory;
@@ -33,9 +35,9 @@ public final class EffectiveConstraintDefinitionImpl implements ConstraintDefini
 
         MaxElementsEffectiveStatementImpl firstMaxElementsStmt = parent
                 .firstEffective(MaxElementsEffectiveStatementImpl.class);
-        String maxElementsArg = (firstMaxElementsStmt == null) ? "unbounded" : firstMaxElementsStmt.argument();
-        if (maxElementsArg.equals("unbounded")) {
-            this.maxElements = Integer.MAX_VALUE;
+        String maxElementsArg = (firstMaxElementsStmt == null) ? UNBOUNDED_STR : firstMaxElementsStmt.argument();
+        if (UNBOUNDED_STR.equals(maxElementsArg)) {
+            this.maxElements = UNBOUNDED_INT;
         } else {
             this.maxElements = Integer.valueOf(maxElementsArg);
         }