Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace += with StringBuilder for whitespace to speed up Tokenizer #615

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ public Token getNext (long max) throws IOException, PdfException
StringBuilder buffer = null;
_state = State.WHITESPACE;
_wsString = EMPTY;

// create string builder for whitespace
StringBuilder ws_buffer = new StringBuilder();
ws_buffer.append(_wsString);

// Numeric sign.
boolean negative = false;
// Floating value.
Expand Down Expand Up @@ -181,13 +186,15 @@ public Token getNext (long max) throws IOException, PdfException
else {
token = null;
}
_wsString = ws_buffer.toString();
return token;
}

if (!_lookAhead) {
_ch = readChar ();
if (_ch < 0) {
_state = State.WHITESPACE;
_wsString = ws_buffer.toString();
throw new PdfMalformedException(MessageConstants.PDF_HUL_64, // PDF-HUL-64
_offset);
}
Expand All @@ -203,7 +210,7 @@ public Token getNext (long max) throws IOException, PdfException
// or continues whitespace.

if (isWhitespace (_ch)) {
_wsString += (char) _ch;
ws_buffer.append((char) _ch);
}
else if (_ch == '[') {
_state = State.WHITESPACE;
Expand Down Expand Up @@ -271,7 +278,8 @@ else if (_state == (State.COMMENT)) {

if (_ch == CR || _ch == LF) {
_state = State.WHITESPACE;
_wsString += (char) _ch;
ws_buffer.append((char) _ch);
_wsString = ws_buffer.toString();
((StringValuedToken) token).setValue(buffer.toString());
if (!token.isPdfACompliant()) {
_pdfACompliant = false;
Expand Down Expand Up @@ -626,6 +634,13 @@ else if (lastch == LF || lastch == CR) {
else {
token = null;
}

if (ws_buffer.length() > 0) {
_wsString = ws_buffer.toString();
} else {
_wsString = EMPTY;
}

}

return token;
Expand Down