Cache group replacement pattern 75/68075/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 30 Jan 2018 21:26:29 +0000 (22:26 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 9 Feb 2018 00:18:32 +0000 (00:18 +0000)
Rather than compiling it over and over again, compile it once.

Change-Id: Id8699f42c081b06197b769f22539e918457b5298
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 73b562bedadd1fbdb1acd5991c39c20c2cc79ec6)

binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/yang/types/TypeProviderImpl.java

index d3f6bac81a7de5c7b90c3f7cc6895f939cfd2726..aa7ff2bbfbff63e27a5c38666975688d7603a207 100644 (file)
@@ -90,6 +90,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
@@ -261,8 +262,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();