lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Dear Lua Author,

I hope this message finds you well. I was studying the Lua source code and came across a condition in the luaH_getint function, which I found intriguing. The code snippet in question is as follows:
```c
else if (!limitequalsasize(t) && (l_castS2U(key) == t->alimit + 1 || l_castS2U(key) - 1u < luaH_realasize(t))) {
    /* key still may be in the array part? */
    t->alimit = cast_uint(key); /* probably '#t' is here now */
    return &t->array[key - 1];
}
```
In this code, I am wondering about the necessity of the `l_castS2U(key) == t->alimit + 1` condition.
It seems to me that if `l_castS2U(key) - 1u < luaH_realasize(t)` is `true`, then the `l_castS2U(key) == t->alimit + 1` condition is irrelevant. Conversely, if `l_castS2U(key) - 1u < luaH_realasize(t)` is `false`, then `l_castS2U(key) == t->alimit + 1` will never be true. As such, I believe that the condition `l_castS2U(key) == t->alimit + 1` might be redundant.

I understand that there could be some reasons for including this condition that I might not be aware of, so I would appreciate it if you could provide some clarification on the rationale behind using both conditions in this case.

Thank you in advance for your time and attention. I am looking forward to your response.

Best regards,

Night Owl