diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-02-24 11:14:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-02-24 11:14:44 -0300 |
commit | 59c88f846d1dcd901a4420651aedf27816618923 (patch) | |
tree | 0e76a066c383cbc99cc2f60b8b4f97c5df45e479 /ltablib.c | |
parent | c03c527fd207b4ad8f5a8e0f4f2c176bd227c979 (diff) | |
download | lua-59c88f846d1dcd901a4420651aedf27816618923.tar.gz lua-59c88f846d1dcd901a4420651aedf27816618923.tar.bz2 lua-59c88f846d1dcd901a4420651aedf27816618923.zip |
Broadening the use of branch hints
More uses of macros 'likely'/'unlikely' (renamed to
'l_likely'/'l_unlikely'), both in range (extended to the
libraries) and in scope (extended to hooks, stack growth).
Diffstat (limited to 'ltablib.c')
-rw-r--r-- | ltablib.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -145,7 +145,7 @@ static int tmove (lua_State *L) { | |||
145 | 145 | ||
146 | static void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) { | 146 | static void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) { |
147 | lua_geti(L, 1, i); | 147 | lua_geti(L, 1, i); |
148 | if (!lua_isstring(L, -1)) | 148 | if (l_unlikely(!lua_isstring(L, -1))) |
149 | luaL_error(L, "invalid value (%s) at index %I in table for 'concat'", | 149 | luaL_error(L, "invalid value (%s) at index %I in table for 'concat'", |
150 | luaL_typename(L, -1), i); | 150 | luaL_typename(L, -1), i); |
151 | luaL_addvalue(b); | 151 | luaL_addvalue(b); |
@@ -196,7 +196,8 @@ static int tunpack (lua_State *L) { | |||
196 | lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1)); | 196 | lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1)); |
197 | if (i > e) return 0; /* empty range */ | 197 | if (i > e) return 0; /* empty range */ |
198 | n = (lua_Unsigned)e - i; /* number of elements minus 1 (avoid overflows) */ | 198 | n = (lua_Unsigned)e - i; /* number of elements minus 1 (avoid overflows) */ |
199 | if (n >= (unsigned int)INT_MAX || !lua_checkstack(L, (int)(++n))) | 199 | if (l_unlikely(n >= (unsigned int)INT_MAX || |
200 | !lua_checkstack(L, (int)(++n)))) | ||
200 | return luaL_error(L, "too many results to unpack"); | 201 | return luaL_error(L, "too many results to unpack"); |
201 | for (; i < e; i++) { /* push arg[i..e - 1] (to avoid overflows) */ | 202 | for (; i < e; i++) { /* push arg[i..e - 1] (to avoid overflows) */ |
202 | lua_geti(L, 1, i); | 203 | lua_geti(L, 1, i); |
@@ -300,14 +301,14 @@ static IdxT partition (lua_State *L, IdxT lo, IdxT up) { | |||
300 | for (;;) { | 301 | for (;;) { |
301 | /* next loop: repeat ++i while a[i] < P */ | 302 | /* next loop: repeat ++i while a[i] < P */ |
302 | while ((void)lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) { | 303 | while ((void)lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) { |
303 | if (i == up - 1) /* a[i] < P but a[up - 1] == P ?? */ | 304 | if (l_unlikely(i == up - 1)) /* a[i] < P but a[up - 1] == P ?? */ |
304 | luaL_error(L, "invalid order function for sorting"); | 305 | luaL_error(L, "invalid order function for sorting"); |
305 | lua_pop(L, 1); /* remove a[i] */ | 306 | lua_pop(L, 1); /* remove a[i] */ |
306 | } | 307 | } |
307 | /* after the loop, a[i] >= P and a[lo .. i - 1] < P */ | 308 | /* after the loop, a[i] >= P and a[lo .. i - 1] < P */ |
308 | /* next loop: repeat --j while P < a[j] */ | 309 | /* next loop: repeat --j while P < a[j] */ |
309 | while ((void)lua_geti(L, 1, --j), sort_comp(L, -3, -1)) { | 310 | while ((void)lua_geti(L, 1, --j), sort_comp(L, -3, -1)) { |
310 | if (j < i) /* j < i but a[j] > P ?? */ | 311 | if (l_unlikely(j < i)) /* j < i but a[j] > P ?? */ |
311 | luaL_error(L, "invalid order function for sorting"); | 312 | luaL_error(L, "invalid order function for sorting"); |
312 | lua_pop(L, 1); /* remove a[j] */ | 313 | lua_pop(L, 1); /* remove a[j] */ |
313 | } | 314 | } |