mirror of
https://github.com/ccxvii/mujs.git
synced 2026-09-27 22:37:47 +08:00
Optimize js_isarrayindex.
Avoid floating point number conversions.
This commit is contained in:
@@ -434,12 +434,20 @@ void js_rot(js_State *J, int n)
|
|||||||
|
|
||||||
/* Property access that takes care of attributes and getters/setters */
|
/* Property access that takes care of attributes and getters/setters */
|
||||||
|
|
||||||
int js_isarrayindex(js_State *J, const char *str, int *idx)
|
int js_isarrayindex(js_State *J, const char *p, int *idx)
|
||||||
{
|
{
|
||||||
char buf[32];
|
int n = 0;
|
||||||
*idx = jsV_numbertointeger(jsV_stringtonumber(J, str));
|
while (*p) {
|
||||||
sprintf(buf, "%u", *idx);
|
int c = *p++;
|
||||||
return !strcmp(buf, str);
|
if (c >= '0' && c <= '9') {
|
||||||
|
if (n > INT_MAX / 10 - 1)
|
||||||
|
return 0;
|
||||||
|
n = n * 10 + (c - '0');
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *idx = n, 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void js_pushrune(js_State *J, Rune rune)
|
static void js_pushrune(js_State *J, Rune rune)
|
||||||
|
|||||||
Reference in New Issue
Block a user