aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-01-30 16:05:23 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-01-30 16:05:23 -0200
commita76fa251998ea83679cfad24542cf4c1aa3d6131 (patch)
tree66bc7f3d28c8dc4b1a1b812aa746a4cbafd649b5 /ltable.c
parentdd3519ab89078fb270797332f0d661b5f6b7612a (diff)
downloadlua-a76fa251998ea83679cfad24542cf4c1aa3d6131.tar.gz
lua-a76fa251998ea83679cfad24542cf4c1aa3d6131.tar.bz2
lua-a76fa251998ea83679cfad24542cf4c1aa3d6131.zip
'ceillog2' now is exported (other modules may need it)
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c24
1 files changed, 3 insertions, 21 deletions
diff --git a/ltable.c b/ltable.c
index def5d581..a92b58ca 100644
--- a/ltable.c
+++ b/ltable.c
@@ -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
189static 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
207static int computesizes (int nums[], int *narray) { 189static 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) {
229static int countint (const TValue *key, int *nums) { 211static 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);