optimization for array part of a Table
This commit is contained in:
30
lobject.c
30
lobject.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lobject.c,v 1.69 2001/03/07 12:27:06 roberto Exp roberto $
|
||||
** $Id: lobject.c,v 1.70 2001/03/26 14:31:49 roberto Exp $
|
||||
** Some generic functions over Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -23,6 +23,34 @@
|
||||
const TObject luaO_nilobject = {LUA_TNIL, {NULL}};
|
||||
|
||||
|
||||
int luaO_log2 (unsigned int x) {
|
||||
static const lu_byte log_8[255] = {
|
||||
0,
|
||||
1,1,
|
||||
2,2,2,2,
|
||||
3,3,3,3,3,3,3,3,
|
||||
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,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,
|
||||
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,
|
||||
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,
|
||||
};
|
||||
if (x & 0xffff0000) {
|
||||
if (x & 0xff000000) return log_8[((x>>24) & 0xff) - 1]+24;
|
||||
else return log_8[((x>>16) & 0xff) - 1]+16;
|
||||
}
|
||||
else {
|
||||
if (x & 0x0000ff00) return log_8[((x>>8) & 0xff) - 1]+8;
|
||||
else if (x) return log_8[(x & 0xff) - 1];
|
||||
return -1; /* special `log' for 0 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int luaO_equalObj (const TObject *t1, const TObject *t2) {
|
||||
if (ttype(t1) != ttype(t2)) return 0;
|
||||
switch (ttype(t1)) {
|
||||
|
||||
Reference in New Issue
Block a user