aboutsummaryrefslogtreecommitdiff
path: root/lcorolib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-02-24 11:14:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-02-24 11:14:44 -0300
commit59c88f846d1dcd901a4420651aedf27816618923 (patch)
tree0e76a066c383cbc99cc2f60b8b4f97c5df45e479 /lcorolib.c
parentc03c527fd207b4ad8f5a8e0f4f2c176bd227c979 (diff)
downloadlua-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 'lcorolib.c')
-rw-r--r--lcorolib.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lcorolib.c b/lcorolib.c
index ed7c58b2..fedbebec 100644
--- a/lcorolib.c
+++ b/lcorolib.c
@@ -31,14 +31,14 @@ static lua_State *getco (lua_State *L) {
31*/ 31*/
32static int auxresume (lua_State *L, lua_State *co, int narg) { 32static int auxresume (lua_State *L, lua_State *co, int narg) {
33 int status, nres; 33 int status, nres;
34 if (!lua_checkstack(co, narg)) { 34 if (l_unlikely(!lua_checkstack(co, narg))) {
35 lua_pushliteral(L, "too many arguments to resume"); 35 lua_pushliteral(L, "too many arguments to resume");
36 return -1; /* error flag */ 36 return -1; /* error flag */
37 } 37 }
38 lua_xmove(L, co, narg); 38 lua_xmove(L, co, narg);
39 status = lua_resume(co, L, narg, &nres); 39 status = lua_resume(co, L, narg, &nres);
40 if (status == LUA_OK || status == LUA_YIELD) { 40 if (l_likely(status == LUA_OK || status == LUA_YIELD)) {
41 if (!lua_checkstack(L, nres + 1)) { 41 if (l_unlikely(!lua_checkstack(L, nres + 1))) {
42 lua_pop(co, nres); /* remove results anyway */ 42 lua_pop(co, nres); /* remove results anyway */
43 lua_pushliteral(L, "too many results to resume"); 43 lua_pushliteral(L, "too many results to resume");
44 return -1; /* error flag */ 44 return -1; /* error flag */
@@ -57,7 +57,7 @@ static int luaB_coresume (lua_State *L) {
57 lua_State *co = getco(L); 57 lua_State *co = getco(L);
58 int r; 58 int r;
59 r = auxresume(L, co, lua_gettop(L) - 1); 59 r = auxresume(L, co, lua_gettop(L) - 1);
60 if (r < 0) { 60 if (l_unlikely(r < 0)) {
61 lua_pushboolean(L, 0); 61 lua_pushboolean(L, 0);
62 lua_insert(L, -2); 62 lua_insert(L, -2);
63 return 2; /* return false + error message */ 63 return 2; /* return false + error message */
@@ -73,7 +73,7 @@ static int luaB_coresume (lua_State *L) {
73static int luaB_auxwrap (lua_State *L) { 73static int luaB_auxwrap (lua_State *L) {
74 lua_State *co = lua_tothread(L, lua_upvalueindex(1)); 74 lua_State *co = lua_tothread(L, lua_upvalueindex(1));
75 int r = auxresume(L, co, lua_gettop(L)); 75 int r = auxresume(L, co, lua_gettop(L));
76 if (r < 0) { /* error? */ 76 if (l_unlikely(r < 0)) { /* error? */
77 int stat = lua_status(co); 77 int stat = lua_status(co);
78 if (stat != LUA_OK && stat != LUA_YIELD) { /* error in the coroutine? */ 78 if (stat != LUA_OK && stat != LUA_YIELD) { /* error in the coroutine? */
79 stat = lua_resetthread(co); /* close its tbc variables */ 79 stat = lua_resetthread(co); /* close its tbc variables */