Welcome! Log In Create A New Profile

Advanced

[njs] Parser: simplified njs_parser_string_create() using existing API.

Dmitry Volyntsev
October 01, 2022 12:14AM
details: https://hg.nginx.org/njs/rev/80b59b59b7d8
branches:
changeset: 1974:80b59b59b7d8
user: Dmitry Volyntsev <xeioex@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;
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Parser: simplified njs_parser_string_create() using existing API.

Dmitry Volyntsev 277 October 01, 2022 12:14AM



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

Online Users

Guests: 73
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready