aboutsummaryrefslogtreecommitdiff
path: root/lstring.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-05-30 11:25:52 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-05-30 11:25:52 -0300
commit34aa0c5bd7493b6e01983df28f04af46a3d99967 (patch)
treeeb58cf48a015be8b9b9c0b3f8c1da14d39f8a065 /lstring.c
parent97e394ba1805fbe394a5704de660403901559e54 (diff)
downloadlua-34aa0c5bd7493b6e01983df28f04af46a3d99967.tar.gz
lua-34aa0c5bd7493b6e01983df28f04af46a3d99967.tar.bz2
lua-34aa0c5bd7493b6e01983df28f04af46a3d99967.zip
new macros 'likely'/'unlikely' with hints for jump predictions
(used only in errors for now)
Diffstat (limited to 'lstring.c')
-rw-r--r--lstring.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lstring.c b/lstring.c
index 29a08212..f1e5d82b 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 2.64 2018/02/15 18:06:24 roberto Exp roberto $ 2** $Id: lstring.c,v 2.65 2018/02/20 16:52:50 roberto Exp roberto $
3** String table (keeps all strings handled by Lua) 3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -99,7 +99,7 @@ void luaS_resize (lua_State *L, int nsize) {
99 if (nsize < osize) /* shrinking table? */ 99 if (nsize < osize) /* shrinking table? */
100 tablerehash(tb->hash, osize, nsize); /* depopulate shrinking part */ 100 tablerehash(tb->hash, osize, nsize); /* depopulate shrinking part */
101 newvect = luaM_reallocvector(L, tb->hash, osize, nsize, TString*); 101 newvect = luaM_reallocvector(L, tb->hash, osize, nsize, TString*);
102 if (newvect == NULL) { /* reallocation failed? */ 102 if (unlikely(newvect == NULL)) { /* reallocation failed? */
103 if (nsize < osize) /* was it shrinking table? */ 103 if (nsize < osize) /* was it shrinking table? */
104 tablerehash(tb->hash, nsize, osize); /* restore to original size */ 104 tablerehash(tb->hash, nsize, osize); /* restore to original size */
105 /* leave table as it was */ 105 /* leave table as it was */
@@ -182,7 +182,7 @@ void luaS_remove (lua_State *L, TString *ts) {
182 182
183 183
184static void growstrtab (lua_State *L, stringtable *tb) { 184static void growstrtab (lua_State *L, stringtable *tb) {
185 if (tb->nuse == MAX_INT) { /* too many strings? */ 185 if (unlikely(tb->nuse == MAX_INT)) { /* too many strings? */
186 luaC_fullgc(L, 1); /* try to free some... */ 186 luaC_fullgc(L, 1); /* try to free some... */
187 if (tb->nuse == MAX_INT) /* still too many? */ 187 if (tb->nuse == MAX_INT) /* still too many? */
188 luaM_error(L); /* cannot even create a message... */ 188 luaM_error(L); /* cannot even create a message... */
@@ -233,7 +233,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
233 return internshrstr(L, str, l); 233 return internshrstr(L, str, l);
234 else { 234 else {
235 TString *ts; 235 TString *ts;
236 if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char)) 236 if (unlikely(l >= (MAX_SIZE - sizeof(TString))/sizeof(char)))
237 luaM_toobig(L); 237 luaM_toobig(L);
238 ts = luaS_createlngstrobj(L, l); 238 ts = luaS_createlngstrobj(L, l);
239 memcpy(getstr(ts), str, l * sizeof(char)); 239 memcpy(getstr(ts), str, l * sizeof(char));
@@ -269,7 +269,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue) {
269 Udata *u; 269 Udata *u;
270 int i; 270 int i;
271 GCObject *o; 271 GCObject *o;
272 if (s > MAX_SIZE - udatamemoffset(nuvalue)) 272 if (unlikely(s > MAX_SIZE - udatamemoffset(nuvalue)))
273 luaM_toobig(L); 273 luaM_toobig(L);
274 o = luaC_newobj(L, LUA_TUSERDATA, sizeudata(nuvalue, s)); 274 o = luaC_newobj(L, LUA_TUSERDATA, sizeudata(nuvalue, s));
275 u = gco2u(o); 275 u = gco2u(o);