[njs] Introduced njs_is_byte_or_ascii_string().
Dmitry Volyntsev
xeioex at nginx.com
Sat Jun 4 07:21:03 UTC 2022
details: https://hg.nginx.org/njs/rev/dd4d6e7cd9ad
branches:
changeset: 1876:dd4d6e7cd9ad
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri Jun 03 23:24:11 2022 -0700
description:
Introduced njs_is_byte_or_ascii_string().
diffstat:
src/njs_regexp.c | 2 +-
src/njs_string.c | 17 ++++++-----------
src/njs_string.h | 7 +++++++
src/njs_vmcode.c | 9 +++------
4 files changed, 17 insertions(+), 18 deletions(-)
diffs (114 lines):
diff -r 5cad81ba52ed -r dd4d6e7cd9ad src/njs_regexp.c
--- a/src/njs_regexp.c Fri Jun 03 23:24:10 2022 -0700
+++ b/src/njs_regexp.c Fri Jun 03 23:24:11 2022 -0700
@@ -1627,7 +1627,7 @@ njs_regexp_prototype_symbol_split(njs_vm
utf8 = NJS_STRING_BYTE;
- if (s.length != 0 && s.length != s.size) {
+ if (!njs_is_byte_or_ascii_string(&s)) {
utf8 = NJS_STRING_UTF8;
}
diff -r 5cad81ba52ed -r dd4d6e7cd9ad src/njs_string.c
--- a/src/njs_string.c Fri Jun 03 23:24:10 2022 -0700
+++ b/src/njs_string.c Fri Jun 03 23:24:11 2022 -0700
@@ -926,7 +926,7 @@ njs_string_prototype_concat(njs_vm_t *vm
size += string.size;
length += string.length;
- if (string.length == 0 && string.size != 0) {
+ if (njs_is_byte_string(&string)) {
mask = 0;
}
}
@@ -2642,8 +2642,7 @@ njs_string_prototype_to_lower_case(njs_v
(void) njs_string_prop(&string, njs_argument(args, 0));
- if (string.length == 0 || string.length == string.size) {
- /* Byte or ASCII string. */
+ if (njs_is_byte_or_ascii_string(&string)) {
p = njs_string_alloc(vm, &vm->retval, string.size, string.length);
if (njs_slow_path(p == NULL)) {
@@ -2714,8 +2713,7 @@ njs_string_prototype_to_upper_case(njs_v
(void) njs_string_prop(&string, njs_argument(args, 0));
- if (string.length == 0 || string.length == string.size) {
- /* Byte or ASCII string. */
+ if (njs_is_byte_or_ascii_string(&string)) {
p = njs_string_alloc(vm, &vm->retval, string.size, string.length);
if (njs_slow_path(p == NULL)) {
@@ -2787,8 +2785,7 @@ njs_string_prototype_trim(njs_vm_t *vm,
start = string.start;
end = string.start + string.size;
- if (string.length == 0 || string.length == string.size) {
- /* Byte or ASCII string. */
+ if (njs_is_byte_or_ascii_string(&string)) {
if (mode & NJS_TRIM_START) {
for ( ;; ) {
@@ -4392,8 +4389,7 @@ njs_string_encode_uri(njs_vm_t *vm, njs_
src = string.start;
end = src + string.size;
- if (string.length == 0 || string.length == string.size) {
- /* Byte or ASCII string. */
+ if (njs_is_byte_or_ascii_string(&string)) {
while (src < end) {
byte = *src++;
@@ -4450,8 +4446,7 @@ njs_string_encode_uri(njs_vm_t *vm, njs_
src = string.start;
- if (string.length == 0 || string.length == string.size) {
- /* Byte or ASCII string. */
+ if (njs_is_byte_or_ascii_string(&string)) {
(void) njs_string_encode(escape, string.size, src, dst);
return NJS_OK;
}
diff -r 5cad81ba52ed -r dd4d6e7cd9ad src/njs_string.h
--- a/src/njs_string.h Fri Jun 03 23:24:10 2022 -0700
+++ b/src/njs_string.h Fri Jun 03 23:24:11 2022 -0700
@@ -105,6 +105,13 @@ njs_is_byte_string(njs_string_prop_t *st
}
+njs_inline njs_bool_t
+njs_is_byte_or_ascii_string(njs_string_prop_t *string)
+{
+ return (string->length == 0 || string->length == string->size);
+}
+
+
njs_inline uint32_t
njs_string_calc_length(njs_utf8_t utf8, const u_char *start, size_t size)
{
diff -r 5cad81ba52ed -r dd4d6e7cd9ad src/njs_vmcode.c
--- a/src/njs_vmcode.c Fri Jun 03 23:24:10 2022 -0700
+++ b/src/njs_vmcode.c Fri Jun 03 23:24:11 2022 -0700
@@ -1606,16 +1606,13 @@ njs_string_concat(njs_vm_t *vm, njs_valu
(void) njs_string_prop(&string1, val1);
(void) njs_string_prop(&string2, val2);
+ length = string1.length + string2.length;
+
/*
* A result of concatenation of Byte and ASCII or UTF-8 strings
* is a Byte string.
*/
- if ((string1.length != 0 || string1.size == 0)
- && (string2.length != 0 || string2.size == 0))
- {
- length = string1.length + string2.length;
-
- } else {
+ if (njs_is_byte_string(&string1) || njs_is_byte_string(&string2)) {
length = 0;
}
More information about the nginx-devel
mailing list