mirror of
https://github.com/lua/lua
synced 2024-12-28 05:09:42 +03:00
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.)
This commit is contained in:
parent
9db4bfed6b
commit
2ff3471722
12
lapi.c
12
lapi.c
@ -86,10 +86,12 @@ static TValue *index2value (lua_State *L, int idx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Convert a valid actual index (not a pseudo-index) to its address.
|
** Convert a valid actual index (not a pseudo-index) to its address.
|
||||||
*/
|
*/
|
||||||
static StkId index2stack (lua_State *L, int idx) {
|
l_sinline StkId index2stack (lua_State *L, int idx) {
|
||||||
CallInfo *ci = L->ci;
|
CallInfo *ci = L->ci;
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
StkId o = ci->func + idx;
|
StkId o = ci->func + idx;
|
||||||
@ -226,7 +228,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) {
|
|||||||
** Note that we move(copy) only the value inside the stack.
|
** Note that we move(copy) only the value inside the stack.
|
||||||
** (We do not move additional fields that may exist.)
|
** (We do not move additional fields that may exist.)
|
||||||
*/
|
*/
|
||||||
static void reverse (lua_State *L, StkId from, StkId to) {
|
l_sinline void reverse (lua_State *L, StkId from, StkId to) {
|
||||||
for (; from < to; from++, to--) {
|
for (; from < to; from++, to--) {
|
||||||
TValue temp;
|
TValue temp;
|
||||||
setobj(L, &temp, s2v(from));
|
setobj(L, &temp, s2v(from));
|
||||||
@ -446,7 +448,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void *touserdata (const TValue *o) {
|
l_sinline void *touserdata (const TValue *o) {
|
||||||
switch (ttype(o)) {
|
switch (ttype(o)) {
|
||||||
case LUA_TUSERDATA: return getudatamem(uvalue(o));
|
case LUA_TUSERDATA: return getudatamem(uvalue(o));
|
||||||
case LUA_TLIGHTUSERDATA: return pvalue(o);
|
case LUA_TLIGHTUSERDATA: return pvalue(o);
|
||||||
@ -638,7 +640,7 @@ LUA_API int lua_pushthread (lua_State *L) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static int auxgetstr (lua_State *L, const TValue *t, const char *k) {
|
l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) {
|
||||||
const TValue *slot;
|
const TValue *slot;
|
||||||
TString *str = luaS_new(L, k);
|
TString *str = luaS_new(L, k);
|
||||||
if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
|
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) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int finishrawget (lua_State *L, const TValue *val) {
|
l_sinline int finishrawget (lua_State *L, const TValue *val) {
|
||||||
if (isempty(val)) /* avoid copying empty items to the stack */
|
if (isempty(val)) /* avoid copying empty items to the stack */
|
||||||
setnilvalue(s2v(L->top));
|
setnilvalue(s2v(L->top));
|
||||||
else
|
else
|
||||||
|
8
ldo.c
8
ldo.c
@ -407,7 +407,7 @@ StkId luaD_tryfuncTM (lua_State *L, StkId func) {
|
|||||||
** expressions, multiple results for tail calls/single parameters)
|
** expressions, multiple results for tail calls/single parameters)
|
||||||
** separated.
|
** separated.
|
||||||
*/
|
*/
|
||||||
static void moveresults (lua_State *L, StkId res, int nres, int wanted) {
|
l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) {
|
||||||
StkId firstresult;
|
StkId firstresult;
|
||||||
int i;
|
int i;
|
||||||
switch (wanted) { /* handle typical cases separately */
|
switch (wanted) { /* handle typical cases separately */
|
||||||
@ -499,8 +499,8 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,
|
l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,
|
||||||
int mask, StkId top) {
|
int mask, StkId top) {
|
||||||
CallInfo *ci = L->ci = next_ci(L); /* new frame */
|
CallInfo *ci = L->ci = next_ci(L); /* new frame */
|
||||||
ci->func = func;
|
ci->func = func;
|
||||||
ci->nresults = nret;
|
ci->nresults = nret;
|
||||||
@ -572,7 +572,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
|
|||||||
** number of recursive invocations in the C stack) or nyci (the same
|
** number of recursive invocations in the C stack) or nyci (the same
|
||||||
** plus increment number of non-yieldable calls).
|
** plus increment number of non-yieldable calls).
|
||||||
*/
|
*/
|
||||||
static void ccall (lua_State *L, StkId func, int nResults, int inc) {
|
l_sinline void ccall (lua_State *L, StkId func, int nResults, int inc) {
|
||||||
CallInfo *ci;
|
CallInfo *ci;
|
||||||
L->nCcalls += inc;
|
L->nCcalls += inc;
|
||||||
if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS))
|
if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS))
|
||||||
|
14
llimits.h
14
llimits.h
@ -165,6 +165,20 @@ typedef LUAI_UACINT l_uacInt;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Inline functions
|
||||||
|
*/
|
||||||
|
#if !defined(LUA_USE_C89)
|
||||||
|
#define l_inline inline
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#define l_inline __inline__
|
||||||
|
#else
|
||||||
|
#define l_inline /* empty */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define l_sinline static l_inline
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** type for virtual-machine instructions;
|
** type for virtual-machine instructions;
|
||||||
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
|
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
|
||||||
|
12
lvm.c
12
lvm.c
@ -406,7 +406,7 @@ static int l_strcmp (const TString *ls, const TString *rs) {
|
|||||||
** from float to int.)
|
** from float to int.)
|
||||||
** When 'f' is NaN, comparisons must result in false.
|
** When 'f' is NaN, comparisons must result in false.
|
||||||
*/
|
*/
|
||||||
static int LTintfloat (lua_Integer i, lua_Number f) {
|
l_sinline int LTintfloat (lua_Integer i, lua_Number f) {
|
||||||
if (l_intfitsf(i))
|
if (l_intfitsf(i))
|
||||||
return luai_numlt(cast_num(i), f); /* compare them as floats */
|
return luai_numlt(cast_num(i), f); /* compare them as floats */
|
||||||
else { /* i < f <=> i < ceil(f) */
|
else { /* i < f <=> i < ceil(f) */
|
||||||
@ -423,7 +423,7 @@ static int LTintfloat (lua_Integer i, lua_Number f) {
|
|||||||
** Check whether integer 'i' is less than or equal to float 'f'.
|
** Check whether integer 'i' is less than or equal to float 'f'.
|
||||||
** See comments on previous function.
|
** See comments on previous function.
|
||||||
*/
|
*/
|
||||||
static int LEintfloat (lua_Integer i, lua_Number f) {
|
l_sinline int LEintfloat (lua_Integer i, lua_Number f) {
|
||||||
if (l_intfitsf(i))
|
if (l_intfitsf(i))
|
||||||
return luai_numle(cast_num(i), f); /* compare them as floats */
|
return luai_numle(cast_num(i), f); /* compare them as floats */
|
||||||
else { /* i <= f <=> i <= floor(f) */
|
else { /* i <= f <=> i <= floor(f) */
|
||||||
@ -440,7 +440,7 @@ static int LEintfloat (lua_Integer i, lua_Number f) {
|
|||||||
** Check whether float 'f' is less than integer 'i'.
|
** Check whether float 'f' is less than integer 'i'.
|
||||||
** See comments on previous function.
|
** See comments on previous function.
|
||||||
*/
|
*/
|
||||||
static int LTfloatint (lua_Number f, lua_Integer i) {
|
l_sinline int LTfloatint (lua_Number f, lua_Integer i) {
|
||||||
if (l_intfitsf(i))
|
if (l_intfitsf(i))
|
||||||
return luai_numlt(f, cast_num(i)); /* compare them as floats */
|
return luai_numlt(f, cast_num(i)); /* compare them as floats */
|
||||||
else { /* f < i <=> floor(f) < i */
|
else { /* f < i <=> floor(f) < i */
|
||||||
@ -457,7 +457,7 @@ static int LTfloatint (lua_Number f, lua_Integer i) {
|
|||||||
** Check whether float 'f' is less than or equal to integer 'i'.
|
** Check whether float 'f' is less than or equal to integer 'i'.
|
||||||
** See comments on previous function.
|
** See comments on previous function.
|
||||||
*/
|
*/
|
||||||
static int LEfloatint (lua_Number f, lua_Integer i) {
|
l_sinline int LEfloatint (lua_Number f, lua_Integer i) {
|
||||||
if (l_intfitsf(i))
|
if (l_intfitsf(i))
|
||||||
return luai_numle(f, cast_num(i)); /* compare them as floats */
|
return luai_numle(f, cast_num(i)); /* compare them as floats */
|
||||||
else { /* f <= i <=> ceil(f) <= i */
|
else { /* f <= i <=> ceil(f) <= i */
|
||||||
@ -473,7 +473,7 @@ static int LEfloatint (lua_Number f, lua_Integer i) {
|
|||||||
/*
|
/*
|
||||||
** Return 'l < r', for numbers.
|
** Return 'l < r', for numbers.
|
||||||
*/
|
*/
|
||||||
static int LTnum (const TValue *l, const TValue *r) {
|
l_sinline int LTnum (const TValue *l, const TValue *r) {
|
||||||
lua_assert(ttisnumber(l) && ttisnumber(r));
|
lua_assert(ttisnumber(l) && ttisnumber(r));
|
||||||
if (ttisinteger(l)) {
|
if (ttisinteger(l)) {
|
||||||
lua_Integer li = ivalue(l);
|
lua_Integer li = ivalue(l);
|
||||||
@ -495,7 +495,7 @@ static int LTnum (const TValue *l, const TValue *r) {
|
|||||||
/*
|
/*
|
||||||
** Return 'l <= r', for numbers.
|
** Return 'l <= r', for numbers.
|
||||||
*/
|
*/
|
||||||
static int LEnum (const TValue *l, const TValue *r) {
|
l_sinline int LEnum (const TValue *l, const TValue *r) {
|
||||||
lua_assert(ttisnumber(l) && ttisnumber(r));
|
lua_assert(ttisnumber(l) && ttisnumber(r));
|
||||||
if (ttisinteger(l)) {
|
if (ttisinteger(l)) {
|
||||||
lua_Integer li = ivalue(l);
|
lua_Integer li = ivalue(l);
|
||||||
|
1
makefile
1
makefile
@ -14,6 +14,7 @@ CWARNSCPP= \
|
|||||||
-Wredundant-decls \
|
-Wredundant-decls \
|
||||||
-Wdisabled-optimization \
|
-Wdisabled-optimization \
|
||||||
-Wdouble-promotion \
|
-Wdouble-promotion \
|
||||||
|
-Wmissing-declarations \
|
||||||
# the next warnings might be useful sometimes,
|
# the next warnings might be useful sometimes,
|
||||||
# but usually they generate too much noise
|
# but usually they generate too much noise
|
||||||
# -Werror \
|
# -Werror \
|
||||||
|
Loading…
Reference in New Issue
Block a user