From 94d40f3980d4f13ed33d1c23fcc8c7aafbd7be59 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 10 Apr 2007 09:18:17 -0300 Subject: luaO_log2 can be private to ltable.c --- ltable.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'ltable.c') diff --git a/ltable.c b/ltable.c index 722e1de3..1b3bc540 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.34 2006/08/07 19:14:30 roberto Exp roberto $ +** $Id: ltable.c,v 2.35 2006/09/11 14:07:24 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -186,6 +186,24 @@ int luaH_next (lua_State *L, Table *t, StkId key) { */ +static int ceillog2 (unsigned int x) { + static const lu_byte log_2[256] = { + 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, + 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, + 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, + 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, + 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, + 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, + 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, + 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 + }; + int l = 0; + x--; + while (x >= 256) { l += 8; x >>= 8; } + return l + log_2[x]; +} + + static int computesizes (int nums[], int *narray) { int i; int twotoi; /* 2^i */ -- cgit v1.2.3-55-g6feb