8223593: Refactor code for reallocating storage

Reviewed-by: prappo, plevart, rriggs, smarks
This commit is contained in:
Ivan Gerasimov 2019-05-21 18:40:29 -07:00
parent 54d0b2a8d6
commit 218204b1a3
11 changed files with 129 additions and 247 deletions

View file

@ -43,6 +43,7 @@ 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.
@ -2315,13 +2316,15 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
}
}
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;
private void append(int ch, int index) {
int len = buffer.length;
if (index - len >= 0) {
len = ArraysSupport.newLength(len,
1 + index - len, /* minimum growth */
len /* preferred growth */);
buffer = Arrays.copyOf(buffer, len);
}
buffer[len] = ch;
buffer[index] = ch;
}
/**