diff options
| -rw-r--r-- | lobject.c | 22 | ||||
| -rw-r--r-- | lobject.h | 3 | ||||
| -rw-r--r-- | ltable.c | 24 |
3 files changed, 25 insertions, 24 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.26 2007/11/09 18:54:25 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.27 2007/12/19 17:24:38 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -33,7 +33,7 @@ const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; | |||
| 33 | ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if | 33 | ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if |
| 34 | ** eeeee != 0 and (xxx) otherwise. | 34 | ** eeeee != 0 and (xxx) otherwise. |
| 35 | */ | 35 | */ |
| 36 | int luaO_int2fb (unsigned int x) { | 36 | int luaO_int2fb (lu_int32 x) { |
| 37 | int e = 0; /* exponent */ | 37 | int e = 0; /* exponent */ |
| 38 | if (x < 8) return x; | 38 | if (x < 8) return x; |
| 39 | while (x >= 0x10) { | 39 | while (x >= 0x10) { |
| @@ -52,6 +52,24 @@ int luaO_fb2int (int x) { | |||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | 54 | ||
| 55 | int luaO_ceillog2 (unsigned int x) { | ||
| 56 | static const lu_byte log_2[256] = { | ||
| 57 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | ||
| 58 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
| 59 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 60 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 61 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 62 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 63 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 64 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 | ||
| 65 | }; | ||
| 66 | int l = 0; | ||
| 67 | x--; | ||
| 68 | while (x >= 256) { l += 8; x >>= 8; } | ||
| 69 | return l + log_2[x]; | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 55 | int luaO_rawequalObj (const TValue *t1, const TValue *t2) { | 73 | int luaO_rawequalObj (const TValue *t1, const TValue *t2) { |
| 56 | if (ttype(t1) != ttype(t2)) return 0; | 74 | if (ttype(t1) != ttype(t2)) return 0; |
| 57 | else switch (ttype(t1)) { | 75 | else switch (ttype(t1)) { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.21 2006/09/11 14:07:24 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.22 2007/04/10 12:18:17 roberto Exp roberto $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -366,6 +366,7 @@ LUAI_DATA const TValue luaO_nilobject_; | |||
| 366 | 366 | ||
| 367 | LUAI_FUNC int luaO_int2fb (unsigned int x); | 367 | LUAI_FUNC int luaO_int2fb (unsigned int x); |
| 368 | LUAI_FUNC int luaO_fb2int (int x); | 368 | LUAI_FUNC int luaO_fb2int (int x); |
| 369 | LUAI_FUNC int luaO_ceillog2 (lu_int32 x); | ||
| 369 | LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); | 370 | LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); |
| 370 | LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); | 371 | LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); |
| 371 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, | 372 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.36 2007/04/10 12:18:17 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.37 2007/04/18 19:24:35 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -186,24 +186,6 @@ int luaH_next (lua_State *L, Table *t, StkId key) { | |||
| 186 | */ | 186 | */ |
| 187 | 187 | ||
| 188 | 188 | ||
| 189 | static int ceillog2 (unsigned int x) { | ||
| 190 | static const lu_byte log_2[256] = { | ||
| 191 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | ||
| 192 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
| 193 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 194 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 195 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 196 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 197 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 198 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 | ||
| 199 | }; | ||
| 200 | int l = 0; | ||
| 201 | x--; | ||
| 202 | while (x >= 256) { l += 8; x >>= 8; } | ||
| 203 | return l + log_2[x]; | ||
| 204 | } | ||
| 205 | |||
| 206 | |||
| 207 | static int computesizes (int nums[], int *narray) { | 189 | static int computesizes (int nums[], int *narray) { |
| 208 | int i; | 190 | int i; |
| 209 | int twotoi; /* 2^i */ | 191 | int twotoi; /* 2^i */ |
| @@ -229,7 +211,7 @@ static int computesizes (int nums[], int *narray) { | |||
| 229 | static int countint (const TValue *key, int *nums) { | 211 | static int countint (const TValue *key, int *nums) { |
| 230 | int k = arrayindex(key); | 212 | int k = arrayindex(key); |
| 231 | if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ | 213 | if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ |
| 232 | nums[ceillog2(k)]++; /* count as such */ | 214 | nums[luaO_ceillog2(k)]++; /* count as such */ |
| 233 | return 1; | 215 | return 1; |
| 234 | } | 216 | } |
| 235 | else | 217 | else |
| @@ -295,7 +277,7 @@ static void setnodevector (lua_State *L, Table *t, int size) { | |||
| 295 | } | 277 | } |
| 296 | else { | 278 | else { |
| 297 | int i; | 279 | int i; |
| 298 | lsize = ceillog2(size); | 280 | lsize = luaO_ceillog2(size); |
| 299 | if (lsize > MAXBITS) | 281 | if (lsize > MAXBITS) |
| 300 | luaG_runerror(L, "table overflow"); | 282 | luaG_runerror(L, "table overflow"); |
| 301 | size = twoto(lsize); | 283 | size = twoto(lsize); |
