@@ -1273,8 +1273,8 @@ static JSValue js_promise_resolve(JSContext *ctx, JSValue this_val,
1273
1273
int argc, JSValue *argv, int magic);
1274
1274
static JSValue js_promise_then(JSContext *ctx, JSValueConst this_val,
1275
1275
int argc, JSValueConst *argv);
1276
- static int js_string_compare(JSContext *ctx,
1277
- const JSString *p1, const JSString *p2);
1276
+ static BOOL js_string_eq(const JSString *p1, const JSString *p2);
1277
+ static int js_string_compare( const JSString *p1, const JSString *p2);
1278
1278
static JSValue JS_ToNumber(JSContext *ctx, JSValue val);
1279
1279
static int JS_SetPropertyValue(JSContext *ctx, JSValue this_obj,
1280
1280
JSValue prop, JSValue val, int flags);
@@ -3367,9 +3367,9 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom)
3367
3367
JS_FreeValue(ctx, num);
3368
3368
return str;
3369
3369
}
3370
- ret = js_string_compare(ctx, p, JS_VALUE_GET_STRING(str));
3370
+ ret = js_string_eq( p, JS_VALUE_GET_STRING(str));
3371
3371
JS_FreeValue(ctx, str);
3372
- if (ret == 0 ) {
3372
+ if (ret) {
3373
3373
return num;
3374
3374
} else {
3375
3375
JS_FreeValue(ctx, num);
@@ -4276,9 +4276,14 @@ static int js_string_memcmp(const JSString *p1, const JSString *p2, int len)
4276
4276
return res;
4277
4277
}
4278
4278
4279
+ static BOOL js_string_eq(const JSString *p1, const JSString *p2) {
4280
+ if (p1->len != p2->len)
4281
+ return FALSE;
4282
+ return js_string_memcmp(p1, p2, p1->len) == 0;
4283
+ }
4284
+
4279
4285
/* return < 0, 0 or > 0 */
4280
- static int js_string_compare(JSContext *ctx,
4281
- const JSString *p1, const JSString *p2)
4286
+ static int js_string_compare(const JSString *p1, const JSString *p2)
4282
4287
{
4283
4288
int res, len;
4284
4289
len = min_int(p1->len, p2->len);
@@ -12939,7 +12944,7 @@ static no_inline int js_relational_slow(JSContext *ctx, JSValue *sp,
12939
12944
JSString *p1, *p2;
12940
12945
p1 = JS_VALUE_GET_STRING(op1);
12941
12946
p2 = JS_VALUE_GET_STRING(op2);
12942
- res = js_string_compare(ctx, p1, p2);
12947
+ res = js_string_compare(p1, p2);
12943
12948
switch(op) {
12944
12949
case OP_lt:
12945
12950
res = (res < 0);
@@ -13230,7 +13235,7 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
13230
13235
} else {
13231
13236
p1 = JS_VALUE_GET_STRING(op1);
13232
13237
p2 = JS_VALUE_GET_STRING(op2);
13233
- res = (js_string_compare(ctx, p1, p2) == 0 );
13238
+ res = js_string_eq( p1, p2);
13234
13239
}
13235
13240
}
13236
13241
break;
@@ -26874,7 +26879,7 @@ static int exported_names_cmp(const void *p1, const void *p2, void *opaque)
26874
26879
/* XXX: raise an error ? */
26875
26880
ret = 0;
26876
26881
} else {
26877
- ret = js_string_compare(ctx, JS_VALUE_GET_STRING(str1),
26882
+ ret = js_string_compare(JS_VALUE_GET_STRING(str1),
26878
26883
JS_VALUE_GET_STRING(str2));
26879
26884
}
26880
26885
JS_FreeValue(ctx, str1);
@@ -39796,7 +39801,7 @@ static int js_array_cmp_generic(const void *a, const void *b, void *opaque) {
39796
39801
goto exception;
39797
39802
bp->str = JS_VALUE_GET_STRING(str);
39798
39803
}
39799
- cmp = js_string_compare(ctx, ap->str, bp->str);
39804
+ cmp = js_string_compare(ap->str, bp->str);
39800
39805
}
39801
39806
if (cmp != 0)
39802
39807
return cmp;
0 commit comments