[XMLBEANS-619] performance change in BindingConfigImpl. Thanks to Peter Keller. This closes #7

git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@1903064 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/xmlbeans/impl/config/BindingConfigImpl.java b/src/main/java/org/apache/xmlbeans/impl/config/BindingConfigImpl.java
index 35c0803..0d1613f 100755
--- a/src/main/java/org/apache/xmlbeans/impl/config/BindingConfigImpl.java
+++ b/src/main/java/org/apache/xmlbeans/impl/config/BindingConfigImpl.java
@@ -46,6 +46,42 @@
     private final List<PrePostExtensionImpl> _prePostExtensions = new ArrayList<>();
     private final Map<QName, UserTypeImpl> _userTypes = new LinkedHashMap<>();
 
+    private static class JavaFilesClasspath {
+
+        private final File[] javaFiles, classpath;
+
+        JavaFilesClasspath(File[] javaFiles, File[] classpath) {
+            this.javaFiles = javaFiles != null ? Arrays.copyOf(javaFiles, javaFiles.length) : new File[0];
+            this.classpath = classpath != null ? Arrays.copyOf(classpath, classpath.length) : new File[0];
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            if ( other == null || ! this.getClass().isInstance(other) )
+                return false;
+            JavaFilesClasspath otherJfc = (JavaFilesClasspath) other;
+            return Arrays.equals(this.javaFiles, otherJfc.javaFiles) && Arrays.equals(this.classpath, otherJfc.classpath);
+        }
+
+        @Override
+        public int hashCode() {
+            return Arrays.hashCode(this.javaFiles) ^ Arrays.hashCode(this.classpath);
+        }
+
+    }
+
+    private static final Map<JavaFilesClasspath, Parser> _parserMap = new HashMap<>();
+
+    private static Parser parserInstance(File[] javaFiles, File[] classpath) {
+        JavaFilesClasspath jfc = new JavaFilesClasspath(javaFiles, classpath);
+        Parser parser = _parserMap.get(jfc);
+        if ( parser == null ) {
+            parser = new Parser(javaFiles, classpath);
+            _parserMap.put(jfc, parser);
+        }
+        return parser;
+    }
+
     public static BindingConfig forConfigDocuments(Config[] configs, File[] javaFiles, File[] classpath) {
         return new BindingConfigImpl(configs, javaFiles, classpath);
     }
@@ -130,7 +166,7 @@
                     InterfaceExtensionImpl.MethodSignatureImpl ms2 = (InterfaceExtensionImpl.MethodSignatureImpl) methodSignatures.get(ms);
                     if (!ms.getReturnType().equals(ms2.getReturnType())) {
                         BindingConfigImpl.error("Colliding methods '" + ms.getSignature() + "' in interfaces " +
-                                                ms.getInterfaceName() + " and " + ms2.getInterfaceName() + ".", null);
+                                ms.getInterfaceName() + " and " + ms2.getInterfaceName() + ".", null);
                     }
 
                     return;
@@ -148,7 +184,7 @@
                 PrePostExtensionImpl b = _prePostExtensions.get(j);
                 if (a.hasNameSetIntersection(b)) {
                     BindingConfigImpl.error("The applicable domain for handler '" + a.getHandlerNameForJavaSource() +
-                                            "' intersects with the one for '" + b.getHandlerNameForJavaSource() + "'.", null);
+                            "' intersects with the one for '" + b.getHandlerNameForJavaSource() + "'.", null);
                 }
             }
         }
@@ -201,7 +237,7 @@
         Extensionconfig.Interface[] intfXO = ext.getInterfaceArray();
         Extensionconfig.PrePostSet ppXO = ext.getPrePostSet();
 
-        Parser loader = new Parser(javaFiles, classpath);
+        Parser loader = parserInstance(javaFiles, classpath);
 
         if (intfXO.length > 0 || ppXO != null) {
             for (Extensionconfig.Interface anInterface : intfXO) {
@@ -213,7 +249,7 @@
     }
 
     private void recordUserTypeSetting(File[] javaFiles, File[] classpath, Usertypeconfig usertypeconfig) {
-        Parser loader = new Parser(javaFiles, classpath);
+        Parser loader = parserInstance(javaFiles, classpath);
         UserTypeImpl userType = UserTypeImpl.newInstance(loader, usertypeconfig);
         _userTypes.put(userType.getName(), userType);
     }
@@ -321,8 +357,8 @@
 
     public InterfaceExtension[] getInterfaceExtensions(String fullJavaName) {
         return _interfaceExtensions.stream().
-            filter(i -> i.contains(fullJavaName)).
-            toArray(InterfaceExtension[]::new);
+                filter(i -> i.contains(fullJavaName)).
+                toArray(InterfaceExtension[]::new);
     }
 
     public PrePostExtension[] getPrePostExtensions() {
@@ -331,7 +367,7 @@
 
     public PrePostExtension getPrePostExtension(String fullJavaName) {
         return _prePostExtensions.stream().
-            filter(p -> p.contains(fullJavaName)).
-            findFirst().orElse(null);
+                filter(p -> p.contains(fullJavaName)).
+                findFirst().orElse(null);
     }
 }