webmcp

changeset 377:ecafddf7ac93

Slightly improved efficiency of (JSON) document proxying in mondelefant_native.c
author jbe
date Sun Nov 15 22:00:12 2015 +0100 (2015-11-15)
parents 4bcedf32b089
children 1625fd905168
files libraries/mondelefant/mondelefant_native.c
line diff
     1.1 --- a/libraries/mondelefant/mondelefant_native.c	Sat Nov 14 17:07:03 2015 +0100
     1.2 +++ b/libraries/mondelefant/mondelefant_native.c	Sun Nov 15 22:00:12 2015 +0100
     1.3 @@ -1549,28 +1549,28 @@
     1.4      }
     1.5      lua_settop(L, 3);
     1.6      // try normal data field info:
     1.7 -    lua_getfield(L, 1, "_data");  // 4
     1.8 +    lua_getfield(L, 1, "_data");  // _data table on stack position 4
     1.9      lua_pushvalue(L, 2);  // 5
    1.10      lua_gettable(L, 4);  // 5
    1.11      if (!lua_isnil(L, 5)) return 1;
    1.12 -    lua_settop(L, 3);  // TODO: keep _data table on stack
    1.13 +    lua_settop(L, 4);  // _data table kept on stack position 4 for later use
    1.14      // try cached referenced object (or cached NULL reference):
    1.15 -    lua_getfield(L, 1, "_ref");  // 4
    1.16 -    lua_pushvalue(L, 2);  // 5
    1.17 -    lua_gettable(L, 4);  // 5
    1.18 -    if (lua_isboolean(L, 5) && !lua_toboolean(L, 5)) {
    1.19 +    lua_getfield(L, 1, "_ref");  // 5
    1.20 +    lua_pushvalue(L, 2);  // 6
    1.21 +    lua_gettable(L, 5);  // 6
    1.22 +    if (lua_isboolean(L, 6) && !lua_toboolean(L, 6)) {
    1.23        lua_pushnil(L);
    1.24        return 1;
    1.25 -    } else if (!lua_isnil(L, 5)) {
    1.26 +    } else if (!lua_isnil(L, 6)) {
    1.27        return 1;
    1.28      }
    1.29 -    lua_settop(L, 3);
    1.30 +    lua_settop(L, 4);
    1.31      // try to load a referenced object:
    1.32 -    lua_pushcfunction(L, mondelefant_class_get_reference);  // 4
    1.33 -    lua_getfield(L, 1, "_class");  // 5
    1.34 -    lua_pushvalue(L, 2);  // 6
    1.35 -    lua_call(L, 2, 1);  // 4
    1.36 -    if (!lua_isnil(L, 4)) {
    1.37 +    lua_pushcfunction(L, mondelefant_class_get_reference);  // 5
    1.38 +    lua_getfield(L, 1, "_class");  // 6
    1.39 +    lua_pushvalue(L, 2);  // 7
    1.40 +    lua_call(L, 2, 1);  // 5
    1.41 +    if (!lua_isnil(L, 5)) {
    1.42        lua_settop(L, 2);
    1.43        lua_getfield(L, 1, "load");  // 3
    1.44        lua_pushvalue(L, 1);  // 4 (self)
    1.45 @@ -1583,11 +1583,12 @@
    1.46        if (lua_isboolean(L, 4) && !lua_toboolean(L, 4)) lua_pushnil(L);  // TODO: use special object instead of false
    1.47        return 1;
    1.48      }
    1.49 -    lua_settop(L, 3);
    1.50 +    lua_settop(L, 4);
    1.51      // try proxy access to document in special column:
    1.52      if (lua_toboolean(L, 3)) {
    1.53 -      lua_getfield(L, 1, "_data");  // 4  TODO: keep on stack from earlier
    1.54 -      lua_insert(L, 3);  // column name to stack position 4
    1.55 +      lua_insert(L, 3);  // switch stack values on position 3 and 4
    1.56 +      // _data table is on stack position 3
    1.57 +      // document column name is on stack position 4
    1.58        lua_gettable(L, 3);  // 4
    1.59        if (!lua_isnil(L, 4)) {
    1.60          lua_pushvalue(L, 2);  // 5

Impressum / About Us