> Only if it is not in there does control flow reach a
hash computation.
I think Soni's question is how to prevent it from doing that hash computation.
From the C API, you can call lua_createtable(L, 256, 0) to create a table with an array part of 256 elements and an empty hash part. Then any calls to luaH_get() with an int in the range 1-256 would be handled by the array part only.
Unfortunately you can't use lua_createtable() or anything like it from Lua code. There are some ugly workarounds described here:
http://lua-users.org/wiki/TablePreallocationAs for why Lua does it that way, I guess it's because searching for an integer key in an empty hash table isn't very expensive. And usually tables will be filled with values.
So what you're proposing is changing the 'else' in luaH_getint() to maybe 'else if (t->sizenode > 0)'? That doesn't seem like a bad idea, if I understand the code correctly. (I'm still learning the Lua internals myself.)
const TValue *luaH_getint (Table *t, lua_Integer key) {
/* ...snip... */