[Pkg-javascript-commits] [node-acorn-jsx] 63/484: reduce array creation in readString
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:05 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit 2bad03e654092143ecb10c0aa0936faee0d4540c
Author: Alistair Braidwood <alistair_braidwood at yahoo.co.uk>
Date: Wed Dec 19 08:22:44 2012 +0000
reduce array creation in readString
---
acorn.js | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/acorn.js b/acorn.js
index c985d9e..bbe56c7 100644
--- a/acorn.js
+++ b/acorn.js
@@ -725,15 +725,17 @@
// Read a string value, interpreting backslash-escapes.
+ var rs_str = [];
+
function readString(quote) {
tokPos++;
- var str = [];
+ rs_str.length = 0;
for (;;) {
if (tokPos >= inputLen) raise(tokStart, "Unterminated string constant");
var ch = input.charCodeAt(tokPos);
if (ch === quote) {
++tokPos;
- return finishToken(_string, String.fromCharCode.apply(null, str));
+ return finishToken(_string, String.fromCharCode.apply(null, rs_str));
}
if (ch === 92) { // '\'
ch = input.charCodeAt(++tokPos);
@@ -744,28 +746,28 @@
++tokPos;
if (octal) {
if (strict) raise(tokPos - 2, "Octal literal in strict mode");
- str.push(parseInt(octal, 8));
+ rs_str.push(parseInt(octal, 8));
tokPos += octal.length - 1;
} else {
switch (ch) {
- case 110: str.push(10); break; // 'n' -> '\n'
- case 114: str.push(13); break; // 'r' -> '\r'
- case 120: str.push(readHexChar(2)); break; // 'x'
- case 117: str.push(readHexChar(4)); break; // 'u'
- case 85: str.push(readHexChar(8)); break; // 'U'
- case 116: str.push(9); break; // 't' -> '\t'
- case 98: str.push(8); break; // 'b' -> '\b'
- case 118: str.push(11); break; // 'v' -> '\u000b'
- case 102: str.push(12); break; // 'f' -> '\f'
- case 48: str.push(0); break; // 0 -> '\0'
+ case 110: rs_str.push(10); break; // 'n' -> '\n'
+ case 114: rs_str.push(13); break; // 'r' -> '\r'
+ case 120: rs_str.push(readHexChar(2)); break; // 'x'
+ case 117: rs_str.push(readHexChar(4)); break; // 'u'
+ case 85: rs_str.push(readHexChar(8)); break; // 'U'
+ case 116: rs_str.push(9); break; // 't' -> '\t'
+ case 98: rs_str.push(8); break; // 'b' -> '\b'
+ case 118: rs_str.push(11); break; // 'v' -> '\u000b'
+ case 102: rs_str.push(12); break; // 'f' -> '\f'
+ case 48: rs_str.push(0); break; // 0 -> '\0'
case 13: if (input.charCodeAt(tokPos) === 10) ++tokPos; // '\r\n'
case 10: break; // ' \n'
- default: str.push(ch); break;
+ default: rs_str.push(ch); break;
}
}
} else {
if (ch === 13 || ch === 10 || ch === 8232 || ch === 8329) raise(tokStart, "Unterminated string constant");
- if (ch !== 92) str.push(ch); // '\'
+ if (ch !== 92) rs_str.push(ch); // '\'
++tokPos;
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list