[njs] Parser: simplified njs_parser_string_create() using existing API.
Dmitry Volyntsev
xeioex at nginx.com
Sat Oct 1 04:12:03 UTC 2022
details: https://hg.nginx.org/njs/rev/80b59b59b7d8
branches:
changeset: 1974:80b59b59b7d8
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri Sep 30 17:40:57 2022 -0700
description:
Parser: simplified njs_parser_string_create() using existing API.
diffstat:
src/njs_parser.c | 39 +++++++++++++--------------------------
1 files changed, 13 insertions(+), 26 deletions(-)
diffs (49 lines):
diff -r 8517d9593c30 -r 80b59b59b7d8 src/njs_parser.c
--- a/src/njs_parser.c Thu Sep 29 18:48:09 2022 -0700
+++ b/src/njs_parser.c Fri Sep 30 17:40:57 2022 -0700
@@ -8307,32 +8307,19 @@ njs_int_t
njs_parser_string_create(njs_vm_t *vm, njs_lexer_token_t *token,
njs_value_t *value)
{
- u_char *dst;
- size_t size, length;
- njs_str_t *src;
- const u_char *p, *end;
- njs_unicode_decode_t ctx;
-
- src = &token->text;
-
- njs_utf8_decode_init(&ctx);
-
- length = njs_utf8_stream_length(&ctx, src->start, src->length, 1, 0, &size);
-
- dst = njs_string_alloc(vm, value, size, length);
- if (njs_slow_path(dst == NULL)) {
- return NJS_ERROR;
- }
-
- p = src->start;
- end = src->start + src->length;
-
- njs_utf8_decode_init(&ctx);
-
- (void) njs_utf8_stream_encode(&ctx, p, end, dst, 1, 0);
-
- if (length > NJS_STRING_MAP_STRIDE && size != length) {
- njs_string_offset_map_init(value->long_string.data->start, size);
+ size_t length;
+ njs_str_t dst;
+
+ length = njs_decode_utf8_length(&token->text, &dst.length);
+ dst.start = njs_string_alloc(vm, value, dst.length, length);
+ if (njs_slow_path(dst.start == NULL)) {
+ return NJS_ERROR;
+ }
+
+ njs_decode_utf8(&dst, &token->text);
+
+ if (length > NJS_STRING_MAP_STRIDE && dst.length != length) {
+ njs_string_offset_map_init(value->long_string.data->start, dst.length);
}
return NJS_OK;
More information about the nginx-devel
mailing list