Author: vgritsenko
Date: Sat Dec 12 23:21:24 2009
New Revision: 890007

URL: http://svn.apache.org/viewvc?rev=890007&view=rev
Log:
fix for REProgram.prefix and flags initialization

Modified:
    jakarta/regexp/trunk/src/java/org/apache/regexp/REProgram.java

Modified: jakarta/regexp/trunk/src/java/org/apache/regexp/REProgram.java
URL: 
http://svn.apache.org/viewvc/jakarta/regexp/trunk/src/java/org/apache/regexp/REProgram.java?rev=890007&r1=890006&r2=890007&view=diff
==============================================================================
--- jakarta/regexp/trunk/src/java/org/apache/regexp/REProgram.java (original)
+++ jakarta/regexp/trunk/src/java/org/apache/regexp/REProgram.java Sat Dec 12 
23:21:24 2009
@@ -112,31 +112,22 @@
         this.prefix = null;
 
         // Try various compile-time optimizations if there's a program
-        if (instruction != null && lenInstruction != 0)
+        if (instruction != null && lenInstruction > 0)
         {
-            // If the first node is a branch
-            if (lenInstruction >= RE.nodeSize && instruction[0 + 
RE.offsetOpcode] == RE.OP_BRANCH)
+            final char firstOp = instruction[RE.offsetOpcode];
+
+            // If the first node is an atom
+            if (firstOp == RE.OP_ATOM)
             {
-                // to the end node
-                int next = (short) instruction[0 + RE.offsetNext];
-                if (instruction[next + RE.offsetOpcode] == RE.OP_END && 
lenInstruction >= (RE.nodeSize * 2))
-                {
-                    final char nextOp = instruction[RE.nodeSize + 
RE.offsetOpcode];
-                    // the branch starts with an atom
-                    if (nextOp == RE.OP_ATOM)
-                    {
-                        // then get that atom as an prefix because there's no 
other choice
-                        int lenAtom = instruction[RE.nodeSize + 
RE.offsetOpdata];
-                        this.prefix = new char[lenAtom];
-                        System.arraycopy(instruction, RE.nodeSize * 2, prefix, 
0, lenAtom);
-                    }
-                    // the branch starts with a BOL
-                    else if (nextOp == RE.OP_BOL)
-                    {
-                        // then set the flag indicating that BOL is present
-                        this.flags |= OPT_HASBOL;
-                    }
-                }
+                // then get that atom as an prefix because there's no other 
choice
+                int lenAtom = instruction[RE.offsetOpdata];
+                this.prefix = new char[lenAtom];
+                System.arraycopy(instruction, RE.nodeSize, prefix, 0, lenAtom);
+
+            // If the first node is a BOL
+            } else if (firstOp == RE.OP_BOL) {
+                // then set the flag indicating that BOL is present
+                this.flags |= OPT_HASBOL;
             }
 
             BackrefScanLoop:



---------------------------------------------------------------------
To unsubscribe, e-mail: regexp-dev-unsubscr...@jakarta.apache.org
For additional commands, e-mail: regexp-dev-h...@jakarta.apache.org

Reply via email to