mirror of https://github.com/rusefi/lua.git
small optimizations in switch order
This commit is contained in:
parent
26679b1a48
commit
0e1058cfdd
10
lapi.c
10
lapi.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 1.17 1998/01/02 17:46:32 roberto Exp roberto $
|
** $Id: lapi.c,v 1.18 1998/01/07 16:26:48 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -39,12 +39,12 @@ static int normalized_type (TObject *o)
|
||||||
{
|
{
|
||||||
int t = ttype(o);
|
int t = ttype(o);
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case LUA_T_CLMARK:
|
|
||||||
return LUA_T_CLOSURE;
|
|
||||||
case LUA_T_PMARK:
|
case LUA_T_PMARK:
|
||||||
return LUA_T_PROTO;
|
return LUA_T_PROTO;
|
||||||
case LUA_T_CMARK:
|
case LUA_T_CMARK:
|
||||||
return LUA_T_CPROTO;
|
return LUA_T_CPROTO;
|
||||||
|
case LUA_T_CLMARK:
|
||||||
|
return LUA_T_CLOSURE;
|
||||||
default:
|
default:
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -382,12 +382,12 @@ int lua_tag (lua_Object lo)
|
||||||
return o->value.ts->u.d.tag;
|
return o->value.ts->u.d.tag;
|
||||||
case LUA_T_ARRAY:
|
case LUA_T_ARRAY:
|
||||||
return o->value.a->htag;
|
return o->value.a->htag;
|
||||||
case LUA_T_CLOSURE: case LUA_T_CLMARK:
|
|
||||||
return o->value.cl->consts[0].ttype;
|
|
||||||
case LUA_T_PMARK:
|
case LUA_T_PMARK:
|
||||||
return LUA_T_PROTO;
|
return LUA_T_PROTO;
|
||||||
case LUA_T_CMARK:
|
case LUA_T_CMARK:
|
||||||
return LUA_T_CPROTO;
|
return LUA_T_CPROTO;
|
||||||
|
case LUA_T_CLOSURE: case LUA_T_CLMARK:
|
||||||
|
return o->value.cl->consts[0].ttype;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
case LUA_T_LINE:
|
case LUA_T_LINE:
|
||||||
lua_error("internal error");
|
lua_error("internal error");
|
||||||
|
|
6
lgc.c
6
lgc.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lgc.c,v 1.13 1997/12/15 16:17:20 roberto Exp roberto $
|
** $Id: lgc.c,v 1.14 1997/12/17 20:48:58 roberto Exp roberto $
|
||||||
** Garbage Collector
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -87,12 +87,12 @@ static int ismarked (TObject *o)
|
||||||
switch (o->ttype) {
|
switch (o->ttype) {
|
||||||
case LUA_T_STRING: case LUA_T_USERDATA:
|
case LUA_T_STRING: case LUA_T_USERDATA:
|
||||||
return o->value.ts->head.marked;
|
return o->value.ts->head.marked;
|
||||||
|
case LUA_T_ARRAY:
|
||||||
|
return o->value.a->head.marked;
|
||||||
case LUA_T_CLOSURE:
|
case LUA_T_CLOSURE:
|
||||||
return o->value.cl->head.marked;
|
return o->value.cl->head.marked;
|
||||||
case LUA_T_PROTO:
|
case LUA_T_PROTO:
|
||||||
return o->value.tf->head.marked;
|
return o->value.tf->head.marked;
|
||||||
case LUA_T_ARRAY:
|
|
||||||
return o->value.a->head.marked;
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
case LUA_T_LINE: case LUA_T_CLMARK:
|
case LUA_T_LINE: case LUA_T_CLMARK:
|
||||||
case LUA_T_CMARK: case LUA_T_PMARK:
|
case LUA_T_CMARK: case LUA_T_PMARK:
|
||||||
|
|
11
llex.c
11
llex.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: llex.c,v 1.11 1997/12/17 20:48:58 roberto Exp roberto $
|
** $Id: llex.c,v 1.12 1997/12/22 17:52:20 roberto Exp roberto $
|
||||||
** Lexical Analizer
|
** Lexical Analizer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -268,15 +268,16 @@ int luaY_lex (YYSTYPE *l)
|
||||||
LS->linelasttoken = LS->linenumber;
|
LS->linelasttoken = LS->linenumber;
|
||||||
while (1) {
|
while (1) {
|
||||||
switch (LS->current) {
|
switch (LS->current) {
|
||||||
case '\n':
|
|
||||||
inclinenumber(LS);
|
|
||||||
LS->linelasttoken = LS->linenumber;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */
|
case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */
|
||||||
next(LS);
|
next(LS);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
case '\n':
|
||||||
|
inclinenumber(LS);
|
||||||
|
LS->linelasttoken = LS->linenumber;
|
||||||
|
continue;
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
save_and_next(LS);
|
save_and_next(LS);
|
||||||
if (LS->current != '-') return '-';
|
if (LS->current != '-') return '-';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lobject.c,v 1.8 1997/12/15 16:17:20 roberto Exp roberto $
|
** $Id: lobject.c,v 1.9 1997/12/26 18:38:16 roberto Exp roberto $
|
||||||
** Some generic functions over Lua objects
|
** Some generic functions over Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -48,9 +48,9 @@ int luaO_equalObj (TObject *t1, TObject *t2)
|
||||||
case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2);
|
case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2);
|
||||||
case LUA_T_STRING: case LUA_T_USERDATA: return svalue(t1) == svalue(t2);
|
case LUA_T_STRING: case LUA_T_USERDATA: return svalue(t1) == svalue(t2);
|
||||||
case LUA_T_ARRAY: return avalue(t1) == avalue(t2);
|
case LUA_T_ARRAY: return avalue(t1) == avalue(t2);
|
||||||
case LUA_T_CLOSURE: return t1->value.cl == t2->value.cl;
|
|
||||||
case LUA_T_PROTO: return tfvalue(t1) == tfvalue(t2);
|
case LUA_T_PROTO: return tfvalue(t1) == tfvalue(t2);
|
||||||
case LUA_T_CPROTO: return fvalue(t1) == fvalue(t2);
|
case LUA_T_CPROTO: return fvalue(t1) == fvalue(t2);
|
||||||
|
case LUA_T_CLOSURE: return t1->value.cl == t2->value.cl;
|
||||||
default:
|
default:
|
||||||
lua_error("internal error in `lua_equalObj'");
|
lua_error("internal error in `lua_equalObj'");
|
||||||
return 0; /* UNREACHEABLE */
|
return 0; /* UNREACHEABLE */
|
||||||
|
|
34
lstrlib.c
34
lstrlib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lstrlib.c,v 1.4 1997/12/15 17:58:49 roberto Exp roberto $
|
** $Id: lstrlib.c,v 1.5 1997/12/17 20:48:58 roberto Exp roberto $
|
||||||
** Standard library for strings and pattern-matching
|
** Standard library for strings and pattern-matching
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -165,14 +165,14 @@ static int matchclass (int c, int cl)
|
||||||
int res;
|
int res;
|
||||||
if (c == 0) return 0;
|
if (c == 0) return 0;
|
||||||
switch (tolower((unsigned char)cl)) {
|
switch (tolower((unsigned char)cl)) {
|
||||||
case 'a' : res = isalpha((unsigned char)c); break;
|
|
||||||
case 'c' : res = iscntrl((unsigned char)c); break;
|
|
||||||
case 'd' : res = isdigit((unsigned char)c); break;
|
|
||||||
case 'l' : res = islower((unsigned char)c); break;
|
|
||||||
case 'p' : res = ispunct((unsigned char)c); break;
|
|
||||||
case 's' : res = isspace((unsigned char)c); break;
|
|
||||||
case 'u' : res = isupper((unsigned char)c); break;
|
|
||||||
case 'w' : res = isalnum((unsigned char)c); break;
|
case 'w' : res = isalnum((unsigned char)c); break;
|
||||||
|
case 'd' : res = isdigit((unsigned char)c); break;
|
||||||
|
case 's' : res = isspace((unsigned char)c); break;
|
||||||
|
case 'a' : res = isalpha((unsigned char)c); break;
|
||||||
|
case 'p' : res = ispunct((unsigned char)c); break;
|
||||||
|
case 'l' : res = islower((unsigned char)c); break;
|
||||||
|
case 'u' : res = isupper((unsigned char)c); break;
|
||||||
|
case 'c' : res = iscntrl((unsigned char)c); break;
|
||||||
default: return (cl == c);
|
default: return (cl == c);
|
||||||
}
|
}
|
||||||
return (islower((unsigned char)cl) ? res : !res);
|
return (islower((unsigned char)cl) ? res : !res);
|
||||||
|
@ -182,12 +182,12 @@ static int matchclass (int c, int cl)
|
||||||
int luaI_singlematch (int c, char *p, char **ep)
|
int luaI_singlematch (int c, char *p, char **ep)
|
||||||
{
|
{
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '\0':
|
|
||||||
*ep = p;
|
|
||||||
return 0;
|
|
||||||
case '.':
|
case '.':
|
||||||
*ep = p+1;
|
*ep = p+1;
|
||||||
return (c != 0);
|
return (c != 0);
|
||||||
|
case '\0':
|
||||||
|
*ep = p;
|
||||||
|
return 0;
|
||||||
case ESC:
|
case ESC:
|
||||||
if (*(++p) == '\0')
|
if (*(++p) == '\0')
|
||||||
luaL_verror("incorrect pattern (ends with `%c')", ESC);
|
luaL_verror("incorrect pattern (ends with `%c')", ESC);
|
||||||
|
@ -294,6 +294,12 @@ static char *match (char *s, char *p, struct Capture *cap)
|
||||||
return res;
|
return res;
|
||||||
p=ep+1; goto init; /* else return match(s, ep+1, cap); */
|
p=ep+1; goto init; /* else return match(s, ep+1, cap); */
|
||||||
}
|
}
|
||||||
|
case '?': { /* optional */
|
||||||
|
char *res;
|
||||||
|
if (s1 && (res = match(s1, ep+1, cap)))
|
||||||
|
return res;
|
||||||
|
p=ep+1; goto init; /* else return match(s, ep+1, cap); */
|
||||||
|
}
|
||||||
case '-': { /* repetition */
|
case '-': { /* repetition */
|
||||||
char *res;
|
char *res;
|
||||||
if ((res = match(s, ep+1, cap)) != 0)
|
if ((res = match(s, ep+1, cap)) != 0)
|
||||||
|
@ -305,12 +311,6 @@ static char *match (char *s, char *p, struct Capture *cap)
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
case '?': { /* optional */
|
|
||||||
char *res;
|
|
||||||
if (s1 && (res = match(s1, ep+1, cap)))
|
|
||||||
return res;
|
|
||||||
p=ep+1; goto init; /* else return match(s, ep+1, cap); */
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
if (s1) { s=s1; p=ep; goto init; } /* return match(s1, ep, cap); */
|
if (s1) { s=s1; p=ep; goto init; } /* return match(s1, ep, cap); */
|
||||||
else return NULL;
|
else return NULL;
|
||||||
|
|
10
ltable.c
10
ltable.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltable.c,v 1.8 1997/12/09 13:35:19 roberto Exp roberto $
|
** $Id: ltable.c,v 1.9 1997/12/15 16:17:20 roberto Exp roberto $
|
||||||
** Lua tables (hash)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -36,8 +36,8 @@ static long int hashindex (TObject *ref)
|
||||||
case LUA_T_STRING: case LUA_T_USERDATA:
|
case LUA_T_STRING: case LUA_T_USERDATA:
|
||||||
h = (IntPoint)tsvalue(ref);
|
h = (IntPoint)tsvalue(ref);
|
||||||
break;
|
break;
|
||||||
case LUA_T_CLOSURE:
|
case LUA_T_ARRAY:
|
||||||
h = (IntPoint)clvalue(ref);
|
h = (IntPoint)avalue(ref);
|
||||||
break;
|
break;
|
||||||
case LUA_T_PROTO:
|
case LUA_T_PROTO:
|
||||||
h = (IntPoint)tfvalue(ref);
|
h = (IntPoint)tfvalue(ref);
|
||||||
|
@ -45,8 +45,8 @@ static long int hashindex (TObject *ref)
|
||||||
case LUA_T_CPROTO:
|
case LUA_T_CPROTO:
|
||||||
h = (IntPoint)fvalue(ref);
|
h = (IntPoint)fvalue(ref);
|
||||||
break;
|
break;
|
||||||
case LUA_T_ARRAY:
|
case LUA_T_CLOSURE:
|
||||||
h = (IntPoint)avalue(ref);
|
h = (IntPoint)clvalue(ref);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
lua_error("unexpected type to index table");
|
lua_error("unexpected type to index table");
|
||||||
|
|
Loading…
Reference in New Issue