diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-04-10 09:18:17 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-04-10 09:18:17 -0300 |
| commit | 94d40f3980d4f13ed33d1c23fcc8c7aafbd7be59 (patch) | |
| tree | fc38e115dc56be07d1fe2edfc4b6fc35b9d9847b | |
| parent | 585b81f91eeff445f77de7276b23c8b8df22e8c5 (diff) | |
| download | lua-94d40f3980d4f13ed33d1c23fcc8c7aafbd7be59.tar.gz lua-94d40f3980d4f13ed33d1c23fcc8c7aafbd7be59.tar.bz2 lua-94d40f3980d4f13ed33d1c23fcc8c7aafbd7be59.zip | |
luaO_log2 can be private to ltable.c
| -rw-r--r-- | lobject.c | 20 | ||||
| -rw-r--r-- | lobject.h | 5 | ||||
| -rw-r--r-- | ltable.c | 20 |
3 files changed, 21 insertions, 24 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.23 2006/07/11 15:53:29 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.24 2006/11/22 11:02:03 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 | */ |
| @@ -51,24 +51,6 @@ int luaO_fb2int (int x) { | |||
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | 53 | ||
| 54 | int luaO_log2 (unsigned int x) { | ||
| 55 | static const lu_byte log_2[256] = { | ||
| 56 | 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, | ||
| 57 | 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, | ||
| 58 | 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, | ||
| 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 | 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, | ||
| 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 | }; | ||
| 65 | int l = -1; | ||
| 66 | while (x >= 256) { l += 8; x >>= 8; } | ||
| 67 | return l + log_2[x]; | ||
| 68 | |||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | int luaO_rawequalObj (const TValue *t1, const TValue *t2) { | 54 | int luaO_rawequalObj (const TValue *t1, const TValue *t2) { |
| 73 | if (ttype(t1) != ttype(t2)) return 0; | 55 | if (ttype(t1) != ttype(t2)) return 0; |
| 74 | else switch (ttype(t1)) { | 56 | else switch (ttype(t1)) { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.20 2006/01/18 11:37:34 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.21 2006/09/11 14:07:24 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 | */ |
| @@ -364,9 +364,6 @@ typedef struct Table { | |||
| 364 | 364 | ||
| 365 | LUAI_DATA const TValue luaO_nilobject_; | 365 | LUAI_DATA const TValue luaO_nilobject_; |
| 366 | 366 | ||
| 367 | #define ceillog2(x) (luaO_log2((x)-1) + 1) | ||
| 368 | |||
| 369 | LUAI_FUNC int luaO_log2 (unsigned int x); | ||
| 370 | LUAI_FUNC int luaO_int2fb (unsigned int x); | 367 | LUAI_FUNC int luaO_int2fb (unsigned int x); |
| 371 | LUAI_FUNC int luaO_fb2int (int x); | 368 | LUAI_FUNC int luaO_fb2int (int x); |
| 372 | LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); | 369 | LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.34 2006/08/07 19:14:30 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.35 2006/09/11 14:07:24 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,6 +186,24 @@ 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 | |||
| 189 | static int computesizes (int nums[], int *narray) { | 207 | static int computesizes (int nums[], int *narray) { |
| 190 | int i; | 208 | int i; |
| 191 | int twotoi; /* 2^i */ | 209 | int twotoi; /* 2^i */ |
