mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-25 15:18:12 +08:00
new string allocator
This commit is contained in:
parent
855fef2606
commit
f058e2a5f3
14
quickjs.c
14
quickjs.c
@ -3874,6 +3874,20 @@ static JSValue string_buffer_end(StringBuffer *s)
|
|||||||
return JS_MKPTR(JS_TAG_STRING, str);
|
return JS_MKPTR(JS_TAG_STRING, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSValue JS_NewStringWLen(JSContext *ctx, size_t buf_len)
|
||||||
|
{
|
||||||
|
JSString *str;
|
||||||
|
if (buf_len <= 0) {
|
||||||
|
return JS_AtomToString(ctx, JS_ATOM_empty_string);
|
||||||
|
}
|
||||||
|
str = js_alloc_string_rt(ctx->rt, buf_len, 0);
|
||||||
|
if (unlikely(!str)){
|
||||||
|
JS_ThrowOutOfMemory(ctx);
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
memset(str->u.str8, 0, buf_len+1);
|
||||||
|
return JS_MKPTR(JS_TAG_STRING, str);
|
||||||
|
}
|
||||||
/* create a string from a UTF-8 buffer */
|
/* create a string from a UTF-8 buffer */
|
||||||
JSValue JS_NewStringLen(JSContext *ctx, const char *buf, size_t buf_len)
|
JSValue JS_NewStringLen(JSContext *ctx, const char *buf, size_t buf_len)
|
||||||
{
|
{
|
||||||
|
@ -696,6 +696,7 @@ int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val);
|
|||||||
/* same as JS_ToInt64() but allow BigInt */
|
/* same as JS_ToInt64() but allow BigInt */
|
||||||
int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val);
|
int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val);
|
||||||
|
|
||||||
|
JSValue JS_NewStringWLen(JSContext *ctx, size_t len);
|
||||||
JSValue JS_NewStringLen(JSContext *ctx, const char *str1, size_t len1);
|
JSValue JS_NewStringLen(JSContext *ctx, const char *str1, size_t len1);
|
||||||
JSValue JS_NewString(JSContext *ctx, const char *str);
|
JSValue JS_NewString(JSContext *ctx, const char *str);
|
||||||
JSValue JS_NewAtomString(JSContext *ctx, const char *str);
|
JSValue JS_NewAtomString(JSContext *ctx, const char *str);
|
||||||
|
Loading…
Reference in New Issue
Block a user