diff options
author | Zhidao HONG <z.hong@f5.com> | 2024-01-31 14:14:28 +0800 |
---|---|---|
committer | Zhidao HONG <z.hong@f5.com> | 2024-02-20 06:09:23 +0800 |
commit | 63507c499e2ff3fa4af416c4d69dbaba2ac1c774 (patch) | |
tree | 18c5a38341dddcf4b268ca6f5c3dff7e259dac64 /src/nxt_var.c | |
parent | 01fd121c4e442039662889bb54ce24f21af649f0 (diff) | |
download | unit-63507c499e2ff3fa4af416c4d69dbaba2ac1c774.tar.gz unit-63507c499e2ff3fa4af416c4d69dbaba2ac1c774.tar.bz2 |
Var: Make nxt_var_cache_value() more general
This commit enhances nxt_var_cache_value() to enable variable access
using string names, complementing the existing reference index method.
The modification ensures future compatibility with njs variable access.
Diffstat (limited to 'src/nxt_var.c')
-rw-r--r-- | src/nxt_var.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/nxt_var.c b/src/nxt_var.c index a297b5b3..53700f40 100644 --- a/src/nxt_var.c +++ b/src/nxt_var.c @@ -54,7 +54,7 @@ static nxt_var_ref_t *nxt_var_ref_get(nxt_tstr_state_t *state, nxt_str_t *name); static nxt_int_t nxt_var_cache_test(nxt_lvlhsh_query_t *lhq, void *data); static nxt_str_t *nxt_var_cache_value(nxt_task_t *task, nxt_tstr_state_t *state, - nxt_var_cache_t *cache, uint32_t index, void *ctx); + nxt_var_cache_t *cache, nxt_var_ref_t *ref, void *ctx); static u_char *nxt_var_next_part(u_char *start, u_char *end, nxt_str_t *part); @@ -205,16 +205,12 @@ nxt_var_cache_test(nxt_lvlhsh_query_t *lhq, void *data) static nxt_str_t * nxt_var_cache_value(nxt_task_t *task, nxt_tstr_state_t *state, - nxt_var_cache_t *cache, uint32_t index, void *ctx) + nxt_var_cache_t *cache, nxt_var_ref_t *ref, void *ctx) { nxt_int_t ret; nxt_str_t *value; - nxt_var_ref_t *ref; nxt_lvlhsh_query_t lhq; - ref = state->var_refs->elts; - ref = &ref[index]; - value = cache->spare; if (value == NULL) { @@ -230,10 +226,10 @@ nxt_var_cache_value(nxt_task_t *task, nxt_tstr_state_t *state, goto not_cached; } - lhq.key_hash = nxt_murmur_hash2_uint32(&index); + lhq.key_hash = nxt_murmur_hash2_uint32(&ref->index); lhq.replace = 0; lhq.key.length = sizeof(uint32_t); - lhq.key.start = (u_char *) &index; + lhq.key.start = (u_char *) &ref->index; lhq.value = value; lhq.proto = &nxt_var_cache_proto; lhq.pool = cache->pool; @@ -493,20 +489,24 @@ nxt_var_interpreter(nxt_task_t *task, nxt_tstr_state_t *state, { u_char *p, *src; size_t length, last, next; + uint32_t index; nxt_str_t *value, **part; nxt_uint_t i; nxt_array_t parts; + nxt_var_ref_t *ref; nxt_var_sub_t *subs; nxt_memzero(&parts, sizeof(nxt_array_t)); nxt_array_init(&parts, cache->pool, sizeof(nxt_str_t *)); + ref = state->var_refs->elts; subs = nxt_var_subs(var); length = var->length; for (i = 0; i < var->vars; i++) { - value = nxt_var_cache_value(task, state, cache, subs[i].index, ctx); + index = subs[i].index; + value = nxt_var_cache_value(task, state, cache, &ref[index], ctx); if (nxt_slow_path(value == NULL)) { return NXT_ERROR; } |