[njs] Added njs_string_slice_string_prop().

Dmitry Volyntsev xeioex at nginx.com
Fri Oct 19 18:30:54 UTC 2018


details:   http://hg.nginx.org/njs/rev/084484ab232b
branches:  
changeset: 627:084484ab232b
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Oct 19 20:55:33 2018 +0300
description:
Added njs_string_slice_string_prop().

diffstat:

 njs/njs_string.c |  22 ++++++++++++++++++----
 njs/njs_string.h |   2 ++
 2 files changed, 20 insertions(+), 4 deletions(-)

diffs (51 lines):

diff -r bd9f53d9de27 -r 084484ab232b njs/njs_string.c
--- a/njs/njs_string.c	Fri Oct 19 20:55:30 2018 +0300
+++ b/njs/njs_string.c	Fri Oct 19 20:55:33 2018 +0300
@@ -1287,8 +1287,8 @@ njs_string_slice_args(njs_slice_prop_t *
 }
 
 
-nxt_noinline njs_ret_t
-njs_string_slice(njs_vm_t *vm, njs_value_t *dst,
+nxt_noinline void
+njs_string_slice_string_prop(njs_string_prop_t *dst,
     const njs_string_prop_t *string, const njs_slice_prop_t *slice)
 {
     size_t        size, n, length;
@@ -1325,8 +1325,22 @@ njs_string_slice(njs_vm_t *vm, njs_value
         length -= n;
     }
 
-    if (nxt_fast_path(size != 0)) {
-        return njs_string_new(vm, dst, start, size, length);
+    dst->start = (u_char *) start;
+    dst->length = length;
+    dst->size = size;
+}
+
+
+nxt_noinline njs_ret_t
+njs_string_slice(njs_vm_t *vm, njs_value_t *dst,
+    const njs_string_prop_t *string, const njs_slice_prop_t *slice)
+{
+    njs_string_prop_t  prop;
+
+    njs_string_slice_string_prop(&prop, string, slice);
+
+    if (nxt_fast_path(prop.size != 0)) {
+        return njs_string_new(vm, dst, prop.start, prop.size, prop.length);
     }
 
     *dst = njs_string_empty;
diff -r bd9f53d9de27 -r 084484ab232b njs/njs_string.h
--- a/njs/njs_string.h	Fri Oct 19 20:55:30 2018 +0300
+++ b/njs/njs_string.h	Fri Oct 19 20:55:33 2018 +0300
@@ -145,6 +145,8 @@ njs_ret_t njs_string_constructor(njs_vm_
     nxt_uint_t nargs, njs_index_t unused);
 nxt_bool_t njs_string_eq(const njs_value_t *val1, const njs_value_t *val2);
 nxt_int_t njs_string_cmp(const njs_value_t *val1, const njs_value_t *val2);
+nxt_noinline void njs_string_slice_string_prop(njs_string_prop_t *dst,
+    const njs_string_prop_t *string, const njs_slice_prop_t *slice);
 njs_ret_t njs_string_slice(njs_vm_t *vm, njs_value_t *dst,
     const njs_string_prop_t *string, const njs_slice_prop_t *slice);
 const u_char *njs_string_offset(const u_char *start, const u_char *end,


More information about the nginx-devel mailing list