Pārlūkot izejas kodu

no more 'luaH_setstr (used only once) + 'luaH_setint' receives value
to be set.

Roberto Ierusalimschy 14 gadi atpakaļ
vecāks
revīzija
92afcf2823
7 mainītis faili ar 25 papildinājumiem un 34 dzēšanām
  1. 2 2
      lapi.c
  2. 7 5
      ldebug.c
  3. 2 2
      llex.c
  4. 3 3
      lstate.c
  5. 7 17
      ltable.c
  6. 2 3
      ltable.h
  7. 2 2
      lvm.c

+ 2 - 2
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 2.148 2011/06/02 19:31:40 roberto Exp roberto $
+** $Id: lapi.c,v 2.149 2011/06/13 14:13:06 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -744,7 +744,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
   api_checknelems(L, 1);
   o = index2addr(L, idx);
   api_check(L, ttistable(o), "table expected");
-  setobj2t(L, luaH_setint(L, hvalue(o), n), L->top-1);
+  luaH_setint(L, hvalue(o), n, L->top - 1);
   luaC_barrierback(L, gcvalue(o), L->top-1);
   L->top--;
   lua_unlock(L);

+ 7 - 5
ldebug.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.c,v 2.81 2011/04/28 14:00:11 roberto Exp roberto $
+** $Id: ldebug.c,v 2.82 2011/06/02 19:31:40 roberto Exp roberto $
 ** Debug Interface
 ** See Copyright Notice in lua.h
 */
@@ -190,12 +190,14 @@ static void collectvalidlines (lua_State *L, Closure *f) {
   }
   else {
     int i;
+    TValue v;
     int *lineinfo = f->l.p->lineinfo;
-    Table *t = luaH_new(L);
-    sethvalue(L, L->top, t);
+    Table *t = luaH_new(L);  /* new table to store active lines */
+    sethvalue(L, L->top, t);  /* push it on stack */
     incr_top(L);
-    for (i=0; i<f->l.p->sizelineinfo; i++)
-      setbvalue(luaH_setint(L, t, lineinfo[i]), 1);
+    setbvalue(&v, 1);  /* boolean 'true' to be the value of all indices */
+    for (i = 0; i < f->l.p->sizelineinfo; i++)  /* for all lines with code */
+      luaH_setint(L, t, lineinfo[i], &v);  /* table[line] = true */
   }
 }
 

+ 2 - 2
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 2.54 2011/07/15 12:30:41 roberto Exp roberto $
+** $Id: llex.c,v 2.55 2011/07/15 12:48:03 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -126,7 +126,7 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
   TValue *o;  /* entry for `str' */
   TString *ts = luaS_newlstr(L, str, l);  /* create new string */
   setsvalue2s(L, L->top++, ts);  /* temporarily anchor it in stack */
-  o = luaH_setstr(L, ls->fs->h, ts);
+  o = luaH_set(L, ls->fs->h, L->top - 1);
   if (ttisnil(o)) {
     setbvalue(o, 1);  /* t[string] = true */
     luaC_checkGC(L);

+ 3 - 3
lstate.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstate.c,v 2.88 2010/12/20 18:17:46 roberto Exp roberto $
+** $Id: lstate.c,v 2.89 2010/12/20 19:40:07 roberto Exp roberto $
 ** Global State
 ** See Copyright Notice in lua.h
 */
@@ -136,10 +136,10 @@ static void init_registry (lua_State *L, global_State *g) {
   luaH_resize(L, registry, LUA_RIDX_LAST, 0);
   /* registry[LUA_RIDX_MAINTHREAD] = L */
   setthvalue(L, &mt, L);
-  setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt);
+  luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &mt);
   /* registry[LUA_RIDX_GLOBALS] = table of globals */
   sethvalue(L, &mt, luaH_new(L));
-  setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt);
+  luaH_setint(L, registry, LUA_RIDX_GLOBALS, &mt);
 }
 
 

+ 7 - 17
ltable.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.c,v 2.59 2011/06/09 18:23:27 roberto Exp roberto $
+** $Id: ltable.c,v 2.60 2011/06/16 14:14:31 roberto Exp roberto $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -314,7 +314,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
     /* re-insert elements from vanishing slice */
     for (i=nasize; i<oldasize; i++) {
       if (!ttisnil(&t->array[i]))
-        setobjt2t(L, luaH_setint(L, t, i+1), &t->array[i]);
+        luaH_setint(L, t, i + 1, &t->array[i]);
     }
     /* shrink array */
     luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
@@ -507,27 +507,17 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
 }
 
 
-TValue *luaH_setint (lua_State *L, Table *t, int key) {
+void luaH_setint (lua_State *L, Table *t, int key, TValue *value) {
   const TValue *p = luaH_getint(t, key);
+  TValue *cell;
   if (p != luaO_nilobject)
-    return cast(TValue *, p);
+    cell = cast(TValue *, p);
   else {
     TValue k;
     setnvalue(&k, cast_num(key));
-    return newkey(L, t, &k);
-  }
-}
-
-
-TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {
-  const TValue *p = luaH_getstr(t, key);
-  if (p != luaO_nilobject)
-    return cast(TValue *, p);
-  else {
-    TValue k;
-    setsvalue(L, &k, key);
-    return newkey(L, t, &k);
+    cell = newkey(L, t, &k);
   }
+  setobj2t(L, cell, value);
 }
 
 

+ 2 - 3
ltable.h

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.h,v 2.13 2009/11/06 17:07:48 roberto Exp roberto $
+** $Id: ltable.h,v 2.14 2010/06/25 12:18:10 roberto Exp roberto $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -17,9 +17,8 @@
 
 
 LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
-LUAI_FUNC TValue *luaH_setint (lua_State *L, Table *t, int key);
+LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value);
 LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
-LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key);
 LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
 LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
 LUAI_FUNC Table *luaH_new (lua_State *L);

+ 2 - 2
lvm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lvm.c,v 2.140 2011/06/02 19:31:40 roberto Exp roberto $
+** $Id: lvm.c,v 2.141 2011/06/09 18:24:22 roberto Exp roberto $
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -808,7 +808,7 @@ void luaV_execute (lua_State *L) {
           luaH_resizearray(L, h, last);  /* pre-allocate it at once */
         for (; n > 0; n--) {
           TValue *val = ra+n;
-          setobj2t(L, luaH_setint(L, h, last--), val);
+          luaH_setint(L, h, last--, val);
           luaC_barrierback(L, obj2gco(h), val);
         }
         L->top = ci->top;  /* correct top (in case of previous open call) */