aboutsummaryrefslogtreecommitdiff
path: root/src/intertyper.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-10-09 22:38:53 -0400
committerAlon Zakai <alonzakai@gmail.com>2013-10-09 22:38:53 -0400
commitf577681a3c6bba87d9e2c51c4a701ee872eba50c (patch)
tree44591d01ab0d41b0fdd059f3de225918822c99d5 /src/intertyper.js
parent9bc421ce5e4273498c929816d4565cc86b2d22c3 (diff)
avoid allocating common tokens repeatedly
Diffstat (limited to 'src/intertyper.js')
-rw-r--r--src/intertyper.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index 9e5f33c8..af9ad934 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -5,6 +5,11 @@
var fastPaths = 0, slowPaths = 0;
+var tokenCache = {};
+['=', 'i32', 'label', ';', '4', '0', '1', '2', '255', 'align', 'i8*', 'i8', 'i16', 'getelementptr', 'inbounds', 'unnamed_addr', 'x', 'load', 'preds', 'br', 'i32*', 'i1', 'store', '<label>', 'constant', 'c', 'private', 'null', 'internal', 'to', 'bitcast', 'define', 'nounwind', 'nocapture', '%this', 'call', '...'].forEach(function(text) { tokenCache[text] = { text: text } });
+
+//var tokenCacheMisses = {};
+
// Line tokenizer
function tokenizer(item, inner) {
//assert(item.lineNum != 40000);
@@ -31,6 +36,15 @@ function tokenizer(item, inner) {
return;
}
+ var cached = tokenCache[text];
+ if (cached) {
+ //assert(cached.text === text);
+ tokens.push(cached);
+ lastToken = cached;
+ return;
+ }
+ //tokenCacheMisses[text] = (misses[text] || 0) + 1;
+
var token = {
text: text
};
@@ -42,6 +56,10 @@ function tokenizer(item, inner) {
}
// merge certain tokens
if (lastToken && isType(lastToken.text) && isFunctionDef(token)) {
+ if (lastToken.text in tokenCache) {
+ // create a copy of the cached value
+ lastToken = tokens[tokens.length-1] = { text: lastToken.text };
+ }
lastToken.text += ' ' + text;
} else if (lastToken && text[0] == '}') { // }, }*, etc.
var openBrace = tokens.length-1;