diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-23 17:18:10 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-23 17:18:10 -0200 |
| commit | 73abfde2ef16223b12cf04800f6e53bfc68ad356 (patch) | |
| tree | c22c497cfd37ab9153e20ab32730bf8a0a4a54ab /lvm.c | |
| parent | 194a4f9710130cdb90df9f4094d81813bdb8ad6b (diff) | |
| download | lua-73abfde2ef16223b12cf04800f6e53bfc68ad356.tar.gz lua-73abfde2ef16223b12cf04800f6e53bfc68ad356.tar.bz2 lua-73abfde2ef16223b12cf04800f6e53bfc68ad356.zip | |
small simplifications around 'luaT_callorderTM'
Diffstat (limited to 'lvm.c')
| -rw-r--r-- | lvm.c | 23 |
1 files changed, 6 insertions, 17 deletions
| @@ -1,8 +1,8 @@ | |||
| 1 | /* | 1 | /* |
| 2 | <<<<<<< lvm.c | 2 | <<<<<<< lvm.c |
| 3 | ** $Id: lvm.c,v 2.313 2017/11/21 14:17:35 roberto Exp roberto $ | 3 | ** $Id: lvm.c,v 2.316 2017/11/23 16:41:16 roberto Exp roberto $ |
| 4 | ======= | 4 | ======= |
| 5 | ** $Id: lvm.c,v 2.315 2017/11/22 19:15:44 roberto Exp $ | 5 | ** $Id: lvm.c,v 2.316 2017/11/23 16:41:16 roberto Exp roberto $ |
| 6 | >>>>>>> 2.315 | 6 | >>>>>>> 2.315 |
| 7 | ** Lua virtual machine | 7 | ** Lua virtual machine |
| 8 | ** See Copyright Notice in lua.h | 8 | ** See Copyright Notice in lua.h |
| @@ -378,13 +378,11 @@ static int LEnum (const TValue *l, const TValue *r) { | |||
| 378 | ** return 'l < r' for non-numbers. | 378 | ** return 'l < r' for non-numbers. |
| 379 | */ | 379 | */ |
| 380 | static int lessthanothers (lua_State *L, const TValue *l, const TValue *r) { | 380 | static int lessthanothers (lua_State *L, const TValue *l, const TValue *r) { |
| 381 | int res; | ||
| 382 | lua_assert(!ttisnumber(l) || !ttisnumber(r)); | 381 | lua_assert(!ttisnumber(l) || !ttisnumber(r)); |
| 383 | if (ttisstring(l) && ttisstring(r)) /* both are strings? */ | 382 | if (ttisstring(l) && ttisstring(r)) /* both are strings? */ |
| 384 | return l_strcmp(tsvalue(l), tsvalue(r)) < 0; | 383 | return l_strcmp(tsvalue(l), tsvalue(r)) < 0; |
| 385 | else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0) /* no metamethod? */ | 384 | else |
| 386 | luaG_ordererror(L, l, r); /* error */ | 385 | return luaT_callorderTM(L, l, r, TM_LT); |
| 387 | return res; | ||
| 388 | } | 386 | } |
| 389 | 387 | ||
| 390 | 388 | ||
| @@ -407,20 +405,11 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { | |||
| 407 | ** keeps that information. | 405 | ** keeps that information. |
| 408 | */ | 406 | */ |
| 409 | static int lessequalothers (lua_State *L, const TValue *l, const TValue *r) { | 407 | static int lessequalothers (lua_State *L, const TValue *l, const TValue *r) { |
| 410 | int res; | ||
| 411 | lua_assert(!ttisnumber(l) || !ttisnumber(r)); | 408 | lua_assert(!ttisnumber(l) || !ttisnumber(r)); |
| 412 | if (ttisstring(l) && ttisstring(r)) /* both are strings? */ | 409 | if (ttisstring(l) && ttisstring(r)) /* both are strings? */ |
| 413 | return l_strcmp(tsvalue(l), tsvalue(r)) <= 0; | 410 | return l_strcmp(tsvalue(l), tsvalue(r)) <= 0; |
| 414 | else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* try 'le' */ | 411 | else |
| 415 | return res; | 412 | return luaT_callorderTM(L, l, r, TM_LE); |
| 416 | else { /* try 'lt': */ | ||
| 417 | L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */ | ||
| 418 | res = luaT_callorderTM(L, r, l, TM_LT); | ||
| 419 | L->ci->callstatus ^= CIST_LEQ; /* clear mark */ | ||
| 420 | if (res < 0) | ||
| 421 | luaG_ordererror(L, l, r); | ||
| 422 | return !res; /* result is negated */ | ||
| 423 | } | ||
| 424 | } | 413 | } |
| 425 | 414 | ||
| 426 | 415 | ||
