summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-08 14:20:43 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-08 15:31:54 +1000
commit66f3914bc7bec57df742ca2126a44e4248aa7f2c (patch)
tree69371a949e1a4eecd6147ad0f3909fc5150ed535 /src
parentb7719b5d3a5794e02a0a81d886a8dd906bda5b51 (diff)
downloadfengari-66f3914bc7bec57df742ca2126a44e4248aa7f2c.tar.gz
fengari-66f3914bc7bec57df742ca2126a44e4248aa7f2c.tar.bz2
fengari-66f3914bc7bec57df742ca2126a44e4248aa7f2c.zip
src/llex.js: Cache tokens in ls.h
Diffstat (limited to 'src')
-rw-r--r--src/llex.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/llex.js b/src/llex.js
index 6e5b853..f2fbd02 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -8,6 +8,7 @@ const ldo = require('./ldo.js');
const ljstype = require('./ljstype.js');
const lobject = require('./lobject.js');
const lstring = require('./lstring.js');
+const ltable = require('./ltable.js');
const llimit = require('./llimit.js');
const TS = defs.thread_status;
const char = defs.char;
@@ -194,9 +195,24 @@ const save_and_next = function(ls) {
next(ls);
};
+/*
+** creates a new string and anchors it in scanner's table so that
+** it will not be collected until the end of the compilation
+** (by that time it should be anchored somewhere)
+*/
const luaX_newstring = function(ls, str) {
- /* TODO: caching in ls.h */
- return lstring.luaS_new(ls.L, str);
+ let L = ls.L;
+ let ts = lstring.luaS_new(L, str);
+ let o = ltable.luaH_set(ls.h, new lobject.TValue(defs.CT.LUA_TLNGSTR, ts));
+ if (o.ttisnil()) { /* not in use yet? */
+ o.setbvalue(true);
+ } else { /* string already present */
+ /* HACK: Workaround lack of ltable 'keyfromval' */
+ let tpair = ls.h.strong.get(lstring.luaS_hash(ts));
+ assert(tpair.value == o);
+ ts = tpair.key.value; /* re-use value previously stored */
+ }
+ return ts;
};
/*