Skip to content

Commit 4fc8143

Browse files
authored
Remove js_new_bf() (#189)
And replace the open-coded JS_NewBigInt() logic at its one call site with the real thing.
1 parent d171290 commit 4fc8143

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

quickjs.c

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11802,17 +11802,6 @@ int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val)
1180211802
return JS_ToBigInt64Free(ctx, pres, js_dup(val));
1180311803
}
1180411804

11805-
static JSBigInt *js_new_bf(JSContext *ctx)
11806-
{
11807-
JSBigInt *p;
11808-
p = js_malloc(ctx, sizeof(*p));
11809-
if (!p)
11810-
return NULL;
11811-
p->header.ref_count = 1;
11812-
bf_init(ctx->bf_ctx, &p->num);
11813-
return p;
11814-
}
11815-
1181611805
static JSValue JS_NewBigInt(JSContext *ctx)
1181711806
{
1181811807
JSBigInt *p;
@@ -33010,33 +32999,25 @@ static int JS_ReadFunctionBytecode(BCReaderState *s, JSFunctionBytecode *b,
3301032999
return 0;
3301133000
}
3301233001

33013-
static JSValue JS_ReadBigInt(BCReaderState *s, int tag)
33002+
static JSValue JS_ReadBigInt(BCReaderState *s)
3301433003
{
33015-
JSValue obj = JS_UNDEFINED;
33004+
JSValue obj;
3301633005
uint8_t v8;
3301733006
int32_t e;
3301833007
uint32_t len;
3301933008
limb_t l, i, n;
33020-
JSBigInt *p;
3302133009
limb_t v;
3302233010
bf_t *a;
3302333011

33024-
p = js_new_bf(s->ctx);
33025-
if (!p)
33012+
obj = JS_NewBigInt(s->ctx);
33013+
if (JS_IsException(obj))
3302633014
goto fail;
33027-
switch(tag) {
33028-
case BC_TAG_BIG_INT:
33029-
obj = JS_MKPTR(JS_TAG_BIG_INT, p);
33030-
break;
33031-
default:
33032-
abort();
33033-
}
3303433015

3303533016
/* sign + exponent */
3303633017
if (bc_get_sleb128(s, &e))
3303733018
goto fail;
3303833019

33039-
a = &p->num;
33020+
a = JS_GetBigInt(obj);
3304033021
a->sign = e & 1;
3304133022
e >>= 1;
3304233023
if (e == 0)
@@ -33775,7 +33756,7 @@ static JSValue JS_ReadObjectRec(BCReaderState *s)
3377533756
obj = JS_ReadObjectValue(s);
3377633757
break;
3377733758
case BC_TAG_BIG_INT:
33778-
obj = JS_ReadBigInt(s, tag);
33759+
obj = JS_ReadBigInt(s);
3377933760
break;
3378033761
case BC_TAG_OBJECT_REFERENCE:
3378133762
{

0 commit comments

Comments
 (0)