< prev index next >

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

Print this page
rev 54801 : [mq]: 8223593-Refactor-code-for-reallocating-storage

*** 41,50 **** --- 41,51 ---- import java.util.Spliterators; import java.util.function.Predicate; import java.util.stream.Stream; import java.util.stream.StreamSupport; + import jdk.internal.util.ArraysSupport; /** * A compiled representation of a regular expression. * * <p> A regular expression, specified as a string, must first be compiled into
*** 2313,2329 **** } else { return newSlice(buffer, first, hasSupplementary); } } ! private void append(int ch, int len) { ! if (len >= buffer.length) { ! int[] tmp = new int[len+len]; ! System.arraycopy(buffer, 0, tmp, 0, len); ! buffer = tmp; } ! buffer[len] = ch; } /** * Parses a backref greedily, taking as many numbers as it * can. The first digit is always treated as a backref, but --- 2314,2331 ---- } else { return newSlice(buffer, first, hasSupplementary); } } ! private void append(int ch, int index) { ! int oldCapacity = buffer.length; ! if (index - oldCapacity >= 0) { ! int newCapacity = ArraysSupport.newCapacity(oldCapacity, ! 1 + index - oldCapacity, oldCapacity); ! buffer = Arrays.copyOf(buffer, newCapacity); } ! buffer[index] = ch; } /** * Parses a backref greedily, taking as many numbers as it * can. The first digit is always treated as a backref, but
< prev index next >