Cache group replacement pattern 56/67756/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 30 Jan 2018 21:26:29 +0000 (22:26 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 30 Jan 2018 21:27:01 +0000 (22:27 +0100)
Rather than compiling it over and over again, compile it once.

Change-Id: Id8699f42c081b06197b769f22539e918457b5298
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/yang/types/TypeProviderImpl.java

index 696acce07b71dbbc8c1df259e6d91b36fdc506f1..cd1492ee39a0772c06547ae3be0e95ac0f64b413 100644 (file)
@@ -91,6 +91,7 @@ import org.slf4j.LoggerFactory;
 
 public final class TypeProviderImpl implements TypeProvider {
     private static final Logger LOG = LoggerFactory.getLogger(TypeProviderImpl.class);
+    private static final Pattern GROUPS_PATTERN = Pattern.compile("\\[(.*?)\\]");
     private static final Pattern NUMBERS_PATTERN = Pattern.compile("[0-9]+\\z");
 
     // Backwards compatibility: Union types used to be instantiated in YANG namespace, which is no longer
@@ -262,8 +263,8 @@ public final class TypeProviderImpl implements TypeProvider {
     private boolean isLeafRefSelfReference(final LeafrefTypeDefinition leafref, final SchemaNode parentNode) {
         final SchemaNode leafRefValueNode;
         final RevisionAwareXPath leafRefXPath = leafref.getPathStatement();
-        final RevisionAwareXPath leafRefStrippedXPath = new RevisionAwareXPathImpl(leafRefXPath.toString()
-                .replaceAll("\\[(.*?)\\]", ""), leafRefXPath.isAbsolute());
+        final RevisionAwareXPath leafRefStrippedXPath = new RevisionAwareXPathImpl(
+            GROUPS_PATTERN.matcher(leafRefXPath.toString()).replaceAll(""), leafRefXPath.isAbsolute());
 
         ///// skip leafrefs in augments - they're checked once augments are resolved
         final Iterator<QName> iterator = parentNode.getPath().getPathFromRoot().iterator();