Bug 489820 part 1 - Make charRefBuf non-growable and have the same lifetime as the tokenizer. r=wchen.

This commit is contained in:
Henri Sivonen
2015-08-25 18:05:45 +03:00
parent c8c7896633
commit ee6c94fc31
3 changed files with 8 additions and 21 deletions

View File

@@ -390,7 +390,7 @@ public class Tokenizer implements Locator {
* Buffer for characters that might form a character reference but may
* end up not forming one.
*/
private @Auto char[] charRefBuf;
private final @Auto char[] charRefBuf;
/**
* Number of significant <code>char</code>s in <code>charRefBuf</code>.
@@ -510,6 +510,9 @@ public class Tokenizer implements Locator {
this.tokenHandler = tokenHandler;
this.encodingDeclarationHandler = null;
this.newAttributesEachTime = newAttributesEachTime;
// &CounterClockwiseContourIntegral; is the longest valid char ref and
// the semicolon never gets appended to the buffer.
this.charRefBuf = new char[32];
this.bmpChar = new char[1];
this.astralChar = new char[2];
this.tagName = null;
@@ -536,6 +539,9 @@ public class Tokenizer implements Locator {
// [NOCPP[
this.newAttributesEachTime = false;
// ]NOCPP]
// &CounterClockwiseContourIntegral; is the longest valid char ref and
// the semicolon never gets appended to the buffer.
this.charRefBuf = new char[32];
this.bmpChar = new char[1];
this.astralChar = new char[2];
this.tagName = null;
@@ -808,11 +814,6 @@ public class Tokenizer implements Locator {
}
@Inline private void appendCharRefBuf(char c) {
if (charRefBufLen == charRefBuf.length) {
char[] newBuf = new char[charRefBuf.length + Tokenizer.BUFFER_GROW_BY];
System.arraycopy(charRefBuf, 0, newBuf, 0, charRefBuf.length);
charRefBuf = newBuf;
}
charRefBuf[charRefBufLen++] = c;
}
@@ -6521,7 +6522,6 @@ public class Tokenizer implements Locator {
public void end() throws SAXException {
strBuf = null;
charRefBuf = null;
doctypeName = null;
if (systemIdentifier != null) {
Portability.releaseString(systemIdentifier);
@@ -6639,9 +6639,6 @@ public class Tokenizer implements Locator {
System.arraycopy(other.strBuf, 0, strBuf, 0, strBufLen);
charRefBufLen = other.charRefBufLen;
if (charRefBufLen > charRefBuf.length) {
charRefBuf = new char[charRefBufLen];
}
System.arraycopy(other.charRefBuf, 0, charRefBuf, 0, charRefBufLen);
stateSave = other.stateSave;
@@ -6714,7 +6711,6 @@ public class Tokenizer implements Locator {
public void initializeWithoutStarting() throws SAXException {
confident = false;
strBuf = new char[1024];
charRefBuf = new char[64];
line = 1;
// [NOCPP[
html4 = false;