You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2010/07/08 22:48:58 UTC

svn commit: r961930 - /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/regex/RegularExpression.java

Author: knoaman
Date: Thu Jul  8 20:48:58 2010
New Revision: 961930

URL: http://svn.apache.org/viewvc?rev=961930&view=rev
Log:
Fix for Jira bug 1456 (https://issues.apache.org/jira/browse/XERCESJ-1456)

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/regex/RegularExpression.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/regex/RegularExpression.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/regex/RegularExpression.java?rev=961930&r1=961929&r2=961930&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/regex/RegularExpression.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/regex/RegularExpression.java Thu Jul  8 20:48:58 2010
@@ -1190,16 +1190,12 @@ public class RegularExpression implement
                     {
                         // Saves current position to avoid zero-width repeats.
                         final int id = op.getData();
-                        int previousOffset = con.offsets[id];
-                        if (previousOffset == offset) {
+                        if (con.closureContexts[id].contains(offset)) {
                             returned = true;
                             break;
                         }
-                        con.offsets[id] = offset;
-                        if (offset < previousOffset) {
-                            op = op.next;
-                            break;
-                        }
+                        
+                        con.closureContexts[id].addOffset(offset);
                     }
                     // fall through
 
@@ -1329,9 +1325,6 @@ public class RegularExpression implement
 
                 switch (op.type) {
                 case Op.CLOSURE:
-                    con.offsets[op.getData()] = offset;
-                    // fall through - same behavior as Op.Question
-
                 case Op.QUESTION:
                     if (retValue < 0) {
                         op = op.next;
@@ -1978,13 +1971,49 @@ public class RegularExpression implement
         }
     }
 
+    static final class ClosureContext {
+        
+        int[] offsets = new int[4];
+        int currentIndex = 0;
+        
+        boolean contains(int offset) {
+            for (int i=0; i<currentIndex;++i) {
+                if (offsets[i] == offset) {
+                    return true;
+                }
+            }
+            return false;
+        }
+        
+        void reset() {
+            currentIndex = 0;
+        }
+
+        void addOffset(int offset) {
+            // We do not check for duplicates, caller is responsible for that
+            if (currentIndex == offsets.length) {
+                offsets = expandOffsets();
+            }
+            offsets[currentIndex++] = offset;
+        }
+        
+        private int[] expandOffsets() {
+            final int len = offsets.length;
+            final int newLen = len << 1;
+            int[] newOffsets = new int[newLen];
+            
+            System.arraycopy(offsets, 0, newOffsets, 0, currentIndex);
+            return newOffsets;
+        }
+    }
+    
     static final class Context {
         int start;
         int limit;
         int length;
         Match match;
         boolean inuse = false;
-        int[] offsets;
+        ClosureContext[] closureContexts;
         
         private StringTarget stringTarget; 
         private CharArrayTarget charArrayTarget;
@@ -1999,9 +2028,17 @@ public class RegularExpression implement
             this.length = this.limit-this.start;
             setInUse(true);
             this.match = null;
-            if (this.offsets == null || this.offsets.length != nofclosures)
-                this.offsets = new int[nofclosures];
-            for (int i = 0;  i < nofclosures;  i ++)  this.offsets[i] = -1;
+            if (this.closureContexts == null || this.closureContexts.length != nofclosures) {
+                this.closureContexts = new ClosureContext[nofclosures];
+            }
+            for (int i = 0;  i < nofclosures;  i ++)  {
+                if (this.closureContexts[i] == null) {
+                    this.closureContexts[i] = new ClosureContext();
+                }
+                else {
+                    this.closureContexts[i].reset();
+                }
+            }
         }
 
         void reset(CharacterIterator target, int start, int limit, int nofclosures) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org