src/share/classes/java/util/regex/Pattern.java

Print this page

        

@@ -1981,10 +1981,11 @@
      * contain alternations.
      */
     private Node expr(Node end) {
         Node prev = null;
         Node firstTail = null;
+        Branch branch = null;
         Node branchConn = null;
 
         for (;;) {
             Node node = sequence(end);
             Node nodeTail = root;      //double return

@@ -2004,21 +2005,21 @@
                     node = null;
                 } else {
                     // the "tail.next" of each atom goes to branchConn
                     nodeTail.next = branchConn;
                 }
-                if (prev instanceof Branch) {
-                    ((Branch)prev).add(node);
+                if (prev == branch) {
+                    branch.add(node);
                 } else {
                     if (prev == end) {
                         prev = null;
                     } else {
                         // replace the "end" with "branchConn" at its tail.next
                         // when put the "prev" into the branch as the first atom.
                         firstTail.next = branchConn;
                     }
-                    prev = new Branch(prev, node, branchConn);
+                    prev = branch = new Branch(prev, node, branchConn);
                 }
             }
             if (peek() != '|') {
                 return prev;
             }