aboutsummaryrefslogtreecommitdiff
path: root/lmem.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 /lmem.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 'lmem.c')
-rw-r--r--lmem.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lmem.c b/lmem.c
index 4822a0ea..e90f991a 100644
--- a/lmem.c
+++ b/lmem.c
@@ -83,7 +83,7 @@ void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize,
83 if (nelems + 1 <= size) /* does one extra element still fit? */ 83 if (nelems + 1 <= size) /* does one extra element still fit? */
84 return block; /* nothing to be done */ 84 return block; /* nothing to be done */
85 if (size >= limit / 2) { /* cannot double it? */ 85 if (size >= limit / 2) { /* cannot double it? */
86 if (unlikely(size >= limit)) /* cannot grow even a little? */ 86 if (l_unlikely(size >= limit)) /* cannot grow even a little? */
87 luaG_runerror(L, "too many %s (limit is %d)", what, limit); 87 luaG_runerror(L, "too many %s (limit is %d)", what, limit);
88 size = limit; /* still have at least one free place */ 88 size = limit; /* still have at least one free place */
89 } 89 }
@@ -164,7 +164,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
164 global_State *g = G(L); 164 global_State *g = G(L);
165 lua_assert((osize == 0) == (block == NULL)); 165 lua_assert((osize == 0) == (block == NULL));
166 newblock = firsttry(g, block, osize, nsize); 166 newblock = firsttry(g, block, osize, nsize);
167 if (unlikely(newblock == NULL && nsize > 0)) { 167 if (l_unlikely(newblock == NULL && nsize > 0)) {
168 if (nsize > osize) /* not shrinking a block? */ 168 if (nsize > osize) /* not shrinking a block? */
169 newblock = tryagain(L, block, osize, nsize); 169 newblock = tryagain(L, block, osize, nsize);
170 if (newblock == NULL) /* still no memory? */ 170 if (newblock == NULL) /* still no memory? */
@@ -179,7 +179,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
179void *luaM_saferealloc_ (lua_State *L, void *block, size_t osize, 179void *luaM_saferealloc_ (lua_State *L, void *block, size_t osize,
180 size_t nsize) { 180 size_t nsize) {
181 void *newblock = luaM_realloc_(L, block, osize, nsize); 181 void *newblock = luaM_realloc_(L, block, osize, nsize);
182 if (unlikely(newblock == NULL && nsize > 0)) /* allocation failed? */ 182 if (l_unlikely(newblock == NULL && nsize > 0)) /* allocation failed? */
183 luaM_error(L); 183 luaM_error(L);
184 return newblock; 184 return newblock;
185} 185}
@@ -191,7 +191,7 @@ void *luaM_malloc_ (lua_State *L, size_t size, int tag) {
191 else { 191 else {
192 global_State *g = G(L); 192 global_State *g = G(L);
193 void *newblock = firsttry(g, NULL, tag, size); 193 void *newblock = firsttry(g, NULL, tag, size);
194 if (unlikely(newblock == NULL)) { 194 if (l_unlikely(newblock == NULL)) {
195 newblock = tryagain(L, NULL, tag, size); 195 newblock = tryagain(L, NULL, tag, size);
196 if (newblock == NULL) 196 if (newblock == NULL)
197 luaM_error(L); 197 luaM_error(L);