# HG changeset patch # User jbe # Date 1447621212 -3600 # Node ID ecafddf7ac936a37f34d7a1878adc779116be030 # Parent 4bcedf32b0890f505ec2196264ec1f21a4568c95 Slightly improved efficiency of (JSON) document proxying in mondelefant_native.c diff -r 4bcedf32b089 -r ecafddf7ac93 libraries/mondelefant/mondelefant_native.c --- a/libraries/mondelefant/mondelefant_native.c Sat Nov 14 17:07:03 2015 +0100 +++ b/libraries/mondelefant/mondelefant_native.c Sun Nov 15 22:00:12 2015 +0100 @@ -1549,28 +1549,28 @@ } lua_settop(L, 3); // try normal data field info: - lua_getfield(L, 1, "_data"); // 4 + lua_getfield(L, 1, "_data"); // _data table on stack position 4 lua_pushvalue(L, 2); // 5 lua_gettable(L, 4); // 5 if (!lua_isnil(L, 5)) return 1; - lua_settop(L, 3); // TODO: keep _data table on stack + lua_settop(L, 4); // _data table kept on stack position 4 for later use // try cached referenced object (or cached NULL reference): - lua_getfield(L, 1, "_ref"); // 4 - lua_pushvalue(L, 2); // 5 - lua_gettable(L, 4); // 5 - if (lua_isboolean(L, 5) && !lua_toboolean(L, 5)) { + lua_getfield(L, 1, "_ref"); // 5 + lua_pushvalue(L, 2); // 6 + lua_gettable(L, 5); // 6 + if (lua_isboolean(L, 6) && !lua_toboolean(L, 6)) { lua_pushnil(L); return 1; - } else if (!lua_isnil(L, 5)) { + } else if (!lua_isnil(L, 6)) { return 1; } - lua_settop(L, 3); + lua_settop(L, 4); // try to load a referenced object: - lua_pushcfunction(L, mondelefant_class_get_reference); // 4 - lua_getfield(L, 1, "_class"); // 5 - lua_pushvalue(L, 2); // 6 - lua_call(L, 2, 1); // 4 - if (!lua_isnil(L, 4)) { + lua_pushcfunction(L, mondelefant_class_get_reference); // 5 + lua_getfield(L, 1, "_class"); // 6 + lua_pushvalue(L, 2); // 7 + lua_call(L, 2, 1); // 5 + if (!lua_isnil(L, 5)) { lua_settop(L, 2); lua_getfield(L, 1, "load"); // 3 lua_pushvalue(L, 1); // 4 (self) @@ -1583,11 +1583,12 @@ if (lua_isboolean(L, 4) && !lua_toboolean(L, 4)) lua_pushnil(L); // TODO: use special object instead of false return 1; } - lua_settop(L, 3); + lua_settop(L, 4); // try proxy access to document in special column: if (lua_toboolean(L, 3)) { - lua_getfield(L, 1, "_data"); // 4 TODO: keep on stack from earlier - lua_insert(L, 3); // column name to stack position 4 + lua_insert(L, 3); // switch stack values on position 3 and 4 + // _data table is on stack position 3 + // document column name is on stack position 4 lua_gettable(L, 3); // 4 if (!lua_isnil(L, 4)) { lua_pushvalue(L, 2); // 5