From 2977fe002407b6f86efa4ba5216f567082f33e45 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 8 May 2017 12:32:08 +1000 Subject: Move string functions to centralised lstring.js --- src/ltable.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/ltable.js') diff --git a/src/ltable.js b/src/ltable.js index 428ee5e..de4c686 100644 --- a/src/ltable.js +++ b/src/ltable.js @@ -6,13 +6,9 @@ const assert = require('assert'); const defs = require('./defs.js'); const ldebug = require('./ldebug.js'); const lobject = require('./lobject.js'); +const lstring = require('./lstring.js'); const CT = defs.constant_types; -/* converts strings (arrays) to a consistent map key */ -const hashstr = function(str) { - return str.map(e => `${e}|`).join(''); -}; - const table_hash = function(key) { switch(key.type) { case CT.LUA_TBOOLEAN: @@ -28,7 +24,7 @@ const table_hash = function(key) { return key.value; case CT.LUA_TSHRSTR: case CT.LUA_TLNGSTR: - return hashstr(key.value); + return lstring.luaS_hash(key.value); default: throw new Error("unknown key type: " + key.type); } @@ -58,7 +54,7 @@ const luaH_getint = function(t, key) { const luaH_getstr = function(t, key) { assert(Array.isArray(key)); - return getgeneric(t, hashstr(key)); + return getgeneric(t, lstring.luaS_hash(key)); }; const luaH_get = function(t, key) { -- cgit v1.2.3-54-g00ecf