diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-09-15 11:18:41 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-09-15 11:18:41 -0300 |
commit | 2ff34717227b8046b0fdcb96206f11f5e888664e (patch) | |
tree | 112f054406eaa82363716882b4300d4ff98ab2ef | |
parent | 9db4bfed6bb9d5828c99c0f24749eedf54d70cc2 (diff) | |
download | lua-2ff34717227b8046b0fdcb96206f11f5e888664e.tar.gz lua-2ff34717227b8046b0fdcb96206f11f5e888664e.tar.bz2 lua-2ff34717227b8046b0fdcb96206f11f5e888664e.zip |
Using 'inline' in some functions
According to ISO C, "making a function an inline function suggests that
calls to the function be as fast as possible." (Not available in C89.)
-rw-r--r-- | lapi.c | 12 | ||||
-rw-r--r-- | ldo.c | 8 | ||||
-rw-r--r-- | llimits.h | 14 | ||||
-rw-r--r-- | lvm.c | 12 | ||||
-rw-r--r-- | makefile | 1 |
5 files changed, 32 insertions, 15 deletions
@@ -86,10 +86,12 @@ static TValue *index2value (lua_State *L, int idx) { | |||
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | |||
90 | |||
89 | /* | 91 | /* |
90 | ** Convert a valid actual index (not a pseudo-index) to its address. | 92 | ** Convert a valid actual index (not a pseudo-index) to its address. |
91 | */ | 93 | */ |
92 | static StkId index2stack (lua_State *L, int idx) { | 94 | l_sinline StkId index2stack (lua_State *L, int idx) { |
93 | CallInfo *ci = L->ci; | 95 | CallInfo *ci = L->ci; |
94 | if (idx > 0) { | 96 | if (idx > 0) { |
95 | StkId o = ci->func + idx; | 97 | StkId o = ci->func + idx; |
@@ -226,7 +228,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) { | |||
226 | ** Note that we move(copy) only the value inside the stack. | 228 | ** Note that we move(copy) only the value inside the stack. |
227 | ** (We do not move additional fields that may exist.) | 229 | ** (We do not move additional fields that may exist.) |
228 | */ | 230 | */ |
229 | static void reverse (lua_State *L, StkId from, StkId to) { | 231 | l_sinline void reverse (lua_State *L, StkId from, StkId to) { |
230 | for (; from < to; from++, to--) { | 232 | for (; from < to; from++, to--) { |
231 | TValue temp; | 233 | TValue temp; |
232 | setobj(L, &temp, s2v(from)); | 234 | setobj(L, &temp, s2v(from)); |
@@ -446,7 +448,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { | |||
446 | } | 448 | } |
447 | 449 | ||
448 | 450 | ||
449 | static void *touserdata (const TValue *o) { | 451 | l_sinline void *touserdata (const TValue *o) { |
450 | switch (ttype(o)) { | 452 | switch (ttype(o)) { |
451 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); | 453 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); |
452 | case LUA_TLIGHTUSERDATA: return pvalue(o); | 454 | case LUA_TLIGHTUSERDATA: return pvalue(o); |
@@ -638,7 +640,7 @@ LUA_API int lua_pushthread (lua_State *L) { | |||
638 | */ | 640 | */ |
639 | 641 | ||
640 | 642 | ||
641 | static int auxgetstr (lua_State *L, const TValue *t, const char *k) { | 643 | l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) { |
642 | const TValue *slot; | 644 | const TValue *slot; |
643 | TString *str = luaS_new(L, k); | 645 | TString *str = luaS_new(L, k); |
644 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { | 646 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { |
@@ -713,7 +715,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | |||
713 | } | 715 | } |
714 | 716 | ||
715 | 717 | ||
716 | static int finishrawget (lua_State *L, const TValue *val) { | 718 | l_sinline int finishrawget (lua_State *L, const TValue *val) { |
717 | if (isempty(val)) /* avoid copying empty items to the stack */ | 719 | if (isempty(val)) /* avoid copying empty items to the stack */ |
718 | setnilvalue(s2v(L->top)); | 720 | setnilvalue(s2v(L->top)); |
719 | else | 721 | else |
@@ -407,7 +407,7 @@ StkId luaD_tryfuncTM (lua_State *L, StkId func) { | |||
407 | ** expressions, multiple results for tail calls/single parameters) | 407 | ** expressions, multiple results for tail calls/single parameters) |
408 | ** separated. | 408 | ** separated. |
409 | */ | 409 | */ |
410 | static void moveresults (lua_State *L, StkId res, int nres, int wanted) { | 410 | l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) { |
411 | StkId firstresult; | 411 | StkId firstresult; |
412 | int i; | 412 | int i; |
413 | switch (wanted) { /* handle typical cases separately */ | 413 | switch (wanted) { /* handle typical cases separately */ |
@@ -499,8 +499,8 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) { | |||
499 | } | 499 | } |
500 | 500 | ||
501 | 501 | ||
502 | static CallInfo *prepCallInfo (lua_State *L, StkId func, int nret, | 502 | l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret, |
503 | int mask, StkId top) { | 503 | int mask, StkId top) { |
504 | CallInfo *ci = L->ci = next_ci(L); /* new frame */ | 504 | CallInfo *ci = L->ci = next_ci(L); /* new frame */ |
505 | ci->func = func; | 505 | ci->func = func; |
506 | ci->nresults = nret; | 506 | ci->nresults = nret; |
@@ -572,7 +572,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { | |||
572 | ** number of recursive invocations in the C stack) or nyci (the same | 572 | ** number of recursive invocations in the C stack) or nyci (the same |
573 | ** plus increment number of non-yieldable calls). | 573 | ** plus increment number of non-yieldable calls). |
574 | */ | 574 | */ |
575 | static void ccall (lua_State *L, StkId func, int nResults, int inc) { | 575 | l_sinline void ccall (lua_State *L, StkId func, int nResults, int inc) { |
576 | CallInfo *ci; | 576 | CallInfo *ci; |
577 | L->nCcalls += inc; | 577 | L->nCcalls += inc; |
578 | if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) | 578 | if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) |
@@ -166,6 +166,20 @@ typedef LUAI_UACINT l_uacInt; | |||
166 | 166 | ||
167 | 167 | ||
168 | /* | 168 | /* |
169 | ** Inline functions | ||
170 | */ | ||
171 | #if !defined(LUA_USE_C89) | ||
172 | #define l_inline inline | ||
173 | #elif defined(__GNUC__) | ||
174 | #define l_inline __inline__ | ||
175 | #else | ||
176 | #define l_inline /* empty */ | ||
177 | #endif | ||
178 | |||
179 | #define l_sinline static l_inline | ||
180 | |||
181 | |||
182 | /* | ||
169 | ** type for virtual-machine instructions; | 183 | ** type for virtual-machine instructions; |
170 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) | 184 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) |
171 | */ | 185 | */ |
@@ -406,7 +406,7 @@ static int l_strcmp (const TString *ls, const TString *rs) { | |||
406 | ** from float to int.) | 406 | ** from float to int.) |
407 | ** When 'f' is NaN, comparisons must result in false. | 407 | ** When 'f' is NaN, comparisons must result in false. |
408 | */ | 408 | */ |
409 | static int LTintfloat (lua_Integer i, lua_Number f) { | 409 | l_sinline int LTintfloat (lua_Integer i, lua_Number f) { |
410 | if (l_intfitsf(i)) | 410 | if (l_intfitsf(i)) |
411 | return luai_numlt(cast_num(i), f); /* compare them as floats */ | 411 | return luai_numlt(cast_num(i), f); /* compare them as floats */ |
412 | else { /* i < f <=> i < ceil(f) */ | 412 | else { /* i < f <=> i < ceil(f) */ |
@@ -423,7 +423,7 @@ static int LTintfloat (lua_Integer i, lua_Number f) { | |||
423 | ** Check whether integer 'i' is less than or equal to float 'f'. | 423 | ** Check whether integer 'i' is less than or equal to float 'f'. |
424 | ** See comments on previous function. | 424 | ** See comments on previous function. |
425 | */ | 425 | */ |
426 | static int LEintfloat (lua_Integer i, lua_Number f) { | 426 | l_sinline int LEintfloat (lua_Integer i, lua_Number f) { |
427 | if (l_intfitsf(i)) | 427 | if (l_intfitsf(i)) |
428 | return luai_numle(cast_num(i), f); /* compare them as floats */ | 428 | return luai_numle(cast_num(i), f); /* compare them as floats */ |
429 | else { /* i <= f <=> i <= floor(f) */ | 429 | else { /* i <= f <=> i <= floor(f) */ |
@@ -440,7 +440,7 @@ static int LEintfloat (lua_Integer i, lua_Number f) { | |||
440 | ** Check whether float 'f' is less than integer 'i'. | 440 | ** Check whether float 'f' is less than integer 'i'. |
441 | ** See comments on previous function. | 441 | ** See comments on previous function. |
442 | */ | 442 | */ |
443 | static int LTfloatint (lua_Number f, lua_Integer i) { | 443 | l_sinline int LTfloatint (lua_Number f, lua_Integer i) { |
444 | if (l_intfitsf(i)) | 444 | if (l_intfitsf(i)) |
445 | return luai_numlt(f, cast_num(i)); /* compare them as floats */ | 445 | return luai_numlt(f, cast_num(i)); /* compare them as floats */ |
446 | else { /* f < i <=> floor(f) < i */ | 446 | else { /* f < i <=> floor(f) < i */ |
@@ -457,7 +457,7 @@ static int LTfloatint (lua_Number f, lua_Integer i) { | |||
457 | ** Check whether float 'f' is less than or equal to integer 'i'. | 457 | ** Check whether float 'f' is less than or equal to integer 'i'. |
458 | ** See comments on previous function. | 458 | ** See comments on previous function. |
459 | */ | 459 | */ |
460 | static int LEfloatint (lua_Number f, lua_Integer i) { | 460 | l_sinline int LEfloatint (lua_Number f, lua_Integer i) { |
461 | if (l_intfitsf(i)) | 461 | if (l_intfitsf(i)) |
462 | return luai_numle(f, cast_num(i)); /* compare them as floats */ | 462 | return luai_numle(f, cast_num(i)); /* compare them as floats */ |
463 | else { /* f <= i <=> ceil(f) <= i */ | 463 | else { /* f <= i <=> ceil(f) <= i */ |
@@ -473,7 +473,7 @@ static int LEfloatint (lua_Number f, lua_Integer i) { | |||
473 | /* | 473 | /* |
474 | ** Return 'l < r', for numbers. | 474 | ** Return 'l < r', for numbers. |
475 | */ | 475 | */ |
476 | static int LTnum (const TValue *l, const TValue *r) { | 476 | l_sinline int LTnum (const TValue *l, const TValue *r) { |
477 | lua_assert(ttisnumber(l) && ttisnumber(r)); | 477 | lua_assert(ttisnumber(l) && ttisnumber(r)); |
478 | if (ttisinteger(l)) { | 478 | if (ttisinteger(l)) { |
479 | lua_Integer li = ivalue(l); | 479 | lua_Integer li = ivalue(l); |
@@ -495,7 +495,7 @@ static int LTnum (const TValue *l, const TValue *r) { | |||
495 | /* | 495 | /* |
496 | ** Return 'l <= r', for numbers. | 496 | ** Return 'l <= r', for numbers. |
497 | */ | 497 | */ |
498 | static int LEnum (const TValue *l, const TValue *r) { | 498 | l_sinline int LEnum (const TValue *l, const TValue *r) { |
499 | lua_assert(ttisnumber(l) && ttisnumber(r)); | 499 | lua_assert(ttisnumber(l) && ttisnumber(r)); |
500 | if (ttisinteger(l)) { | 500 | if (ttisinteger(l)) { |
501 | lua_Integer li = ivalue(l); | 501 | lua_Integer li = ivalue(l); |
@@ -14,6 +14,7 @@ CWARNSCPP= \ | |||
14 | -Wredundant-decls \ | 14 | -Wredundant-decls \ |
15 | -Wdisabled-optimization \ | 15 | -Wdisabled-optimization \ |
16 | -Wdouble-promotion \ | 16 | -Wdouble-promotion \ |
17 | -Wmissing-declarations \ | ||
17 | # the next warnings might be useful sometimes, | 18 | # the next warnings might be useful sometimes, |
18 | # but usually they generate too much noise | 19 | # but usually they generate too much noise |
19 | # -Werror \ | 20 | # -Werror \ |