Merge pull request #5063 from Snuffleupagus/ps-parser-avoid-intermediate-string-creation
Avoid creating intermediate strings in the PostScriptLexer
This commit is contained in:
commit
6038ee7cff
@ -137,6 +137,8 @@ var PostScriptLexer = (function PostScriptLexerClosure() {
|
|||||||
function PostScriptLexer(stream) {
|
function PostScriptLexer(stream) {
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.nextChar();
|
this.nextChar();
|
||||||
|
|
||||||
|
this.strBuf = [];
|
||||||
}
|
}
|
||||||
PostScriptLexer.prototype = {
|
PostScriptLexer.prototype = {
|
||||||
nextChar: function PostScriptLexer_nextChar() {
|
nextChar: function PostScriptLexer_nextChar() {
|
||||||
@ -177,11 +179,15 @@ var PostScriptLexer = (function PostScriptLexerClosure() {
|
|||||||
return PostScriptToken.RBRACE;
|
return PostScriptToken.RBRACE;
|
||||||
}
|
}
|
||||||
// operator
|
// operator
|
||||||
var str = String.fromCharCode(ch);
|
var strBuf = this.strBuf;
|
||||||
|
strBuf.length = 0;
|
||||||
|
strBuf[0] = String.fromCharCode(ch);
|
||||||
|
|
||||||
while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
|
while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
|
||||||
((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
|
((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
|
||||||
str += String.fromCharCode(ch);
|
strBuf.push(String.fromCharCode(ch));
|
||||||
}
|
}
|
||||||
|
var str = strBuf.join('');
|
||||||
switch (str.toLowerCase()) {
|
switch (str.toLowerCase()) {
|
||||||
case 'if':
|
case 'if':
|
||||||
return PostScriptToken.IF;
|
return PostScriptToken.IF;
|
||||||
@ -193,16 +199,19 @@ var PostScriptLexer = (function PostScriptLexerClosure() {
|
|||||||
},
|
},
|
||||||
getNumber: function PostScriptLexer_getNumber() {
|
getNumber: function PostScriptLexer_getNumber() {
|
||||||
var ch = this.currentChar;
|
var ch = this.currentChar;
|
||||||
var str = String.fromCharCode(ch);
|
var strBuf = this.strBuf;
|
||||||
|
strBuf.length = 0;
|
||||||
|
strBuf[0] = String.fromCharCode(ch);
|
||||||
|
|
||||||
while ((ch = this.nextChar()) >= 0) {
|
while ((ch = this.nextChar()) >= 0) {
|
||||||
if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
|
if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
|
||||||
ch === 0x2D || ch === 0x2E) { // '-', '.'
|
ch === 0x2D || ch === 0x2E) { // '-', '.'
|
||||||
str += String.fromCharCode(ch);
|
strBuf.push(String.fromCharCode(ch));
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var value = parseFloat(str);
|
var value = parseFloat(strBuf.join(''));
|
||||||
if (isNaN(value)) {
|
if (isNaN(value)) {
|
||||||
error('Invalid floating point number: ' + value);
|
error('Invalid floating point number: ' + value);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user