Welcome! Log In Create A New Profile

Advanced

[njs] Optimized qjs_to_bytes().

Anonymous User
October 08, 2024 07:06PM
details: https://github.com/nginx/njs/commit/39a2d4bf212346d1487e4d27383453cafefa17ea
branches: master
commit: 39a2d4bf212346d1487e4d27383453cafefa17ea
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon, 7 Oct 2024 22:46:40 -0700
description:
Optimized qjs_to_bytes().

Doing JS_IsString() check first before a heavy-weight call to
JS_GetTypedArrayBuffer() which throws an exception when argument is not
a typed array.

---
src/qjs.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/qjs.c b/src/qjs.c
index e7653569..3d378fcc 100644
--- a/src/qjs.c
+++ b/src/qjs.c
@@ -175,6 +175,10 @@ qjs_to_bytes(JSContext *ctx, qjs_bytes_t *bytes, JSValueConst value)
size_t byte_offset, byte_length;
JSValue val;

+ if (JS_IsString(value)) {
+ goto string;
+ }
+
val = JS_GetTypedArrayBuffer(ctx, value, &byte_offset, &byte_length, NULL);
if (!JS_IsException(val)) {
bytes->start = JS_GetArrayBuffer(ctx, &bytes->length, val);
@@ -195,8 +199,6 @@ qjs_to_bytes(JSContext *ctx, qjs_bytes_t *bytes, JSValueConst value)
return 0;
}

- bytes->tag = JS_TAG_STRING;
-
if (!JS_IsString(value)) {
val = JS_ToString(ctx, value);

@@ -209,6 +211,9 @@ qjs_to_bytes(JSContext *ctx, qjs_bytes_t *bytes, JSValueConst value)
}
}

+string:
+
+ bytes->tag = JS_TAG_STRING;
bytes->start = (u_char *) JS_ToCStringLen(ctx, &bytes->length, value);

return (bytes->start != NULL) ? 0 : -1;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Optimized qjs_to_bytes().

Anonymous User 181 October 08, 2024 07:06PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 95
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready