[njs] Optimized string creation with ASCII input.

Dmitry Volyntsev xeioex at nginx.com
Sat May 18 04:55:24 UTC 2024


details:   https://hg.nginx.org/njs/rev/dec46ad52e9a
branches:  
changeset: 2328:dec46ad52e9a
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri May 17 21:54:49 2024 -0700
description:
Optimized string creation with ASCII input.

diffstat:

 src/njs_string.c |  12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diffs (24 lines):

diff -r f474755a4dce -r dec46ad52e9a src/njs_string.c
--- a/src/njs_string.c	Fri May 17 18:36:12 2024 -0700
+++ b/src/njs_string.c	Fri May 17 21:54:49 2024 -0700
@@ -130,8 +130,20 @@ njs_int_t
 njs_string_create(njs_vm_t *vm, njs_value_t *value, const char *src,
     size_t size)
 {
+    u_char     *p, *p_end;
     njs_str_t  str;
 
+    p = (u_char *) src;
+    p_end = p + size;
+
+    while (p < p_end && *p < 0x80) {
+          p++;
+    }
+
+    if (p == p_end) {
+        return njs_string_new(vm, value, (u_char *) src, size, size);
+    }
+
     str.start = (u_char *) src;
     str.length = size;
 


More information about the nginx-devel mailing list