aboutsummaryrefslogtreecommitdiff
path: root/src/njs_scope.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/njs_scope.c')
-rw-r--r--src/njs_scope.c76
1 files changed, 31 insertions, 45 deletions
diff --git a/src/njs_scope.c b/src/njs_scope.c
index 304e4e33..cd1176a2 100644
--- a/src/njs_scope.c
+++ b/src/njs_scope.c
@@ -25,22 +25,6 @@ njs_scope_temp_index(njs_parser_scope_t *scope)
}
-njs_value_t *
-njs_scope_create_index_value(njs_vm_t *vm, njs_index_t index)
-{
- njs_value_t *value;
-
- value = njs_mp_alloc(vm->mem_pool, sizeof(njs_value_t));
- if (njs_slow_path(value == NULL)) {
- return NULL;
- }
-
- njs_scope_value_set(vm, index, value);
-
- return value;
-}
-
-
njs_value_t **
njs_scope_make(njs_vm_t *vm, uint32_t count)
{
@@ -119,12 +103,12 @@ njs_scope_value_get(njs_vm_t *vm, njs_index_t index)
static njs_int_t
-njs_scope_values_hash_test(njs_lvlhsh_query_t *lhq, void *data)
+njs_scope_values_hash_test(njs_flathsh_query_t *fhq, void *data)
{
njs_str_t string;
njs_value_t *value;
- value = data;
+ value = *(njs_value_t **) data;
if (njs_is_string(value)) {
/* parser strings are always initialized. */
@@ -135,8 +119,8 @@ njs_scope_values_hash_test(njs_lvlhsh_query_t *lhq, void *data)
string.length = sizeof(njs_value_t);
}
- if (lhq->key.length == string.length
- && memcmp(lhq->key.start, string.start, string.length) == 0)
+ if (fhq->key.length == string.length
+ && memcmp(fhq->key.start, string.start, string.length) == 0)
{
return NJS_OK;
}
@@ -145,13 +129,12 @@ njs_scope_values_hash_test(njs_lvlhsh_query_t *lhq, void *data)
}
-static const njs_lvlhsh_proto_t njs_values_hash_proto
+static const njs_flathsh_proto_t njs_values_hash_proto
njs_aligned(64) =
{
- NJS_LVLHSH_DEFAULT,
njs_scope_values_hash_test,
- njs_lvlhsh_alloc,
- njs_lvlhsh_free,
+ njs_flathsh_proto_alloc,
+ njs_flathsh_proto_free,
};
@@ -164,15 +147,16 @@ static njs_value_t *
njs_scope_value_index(njs_vm_t *vm, const njs_value_t *src, njs_uint_t runtime,
njs_index_t **index)
{
- u_char *start;
- uint32_t value_size, size, length;
- njs_int_t ret;
- njs_str_t str;
- njs_bool_t is_string;
- njs_value_t *value;
- njs_string_t *string;
- njs_lvlhsh_t *values_hash;
- njs_lvlhsh_query_t lhq;
+ u_char *start;
+ uint32_t value_size, size, length;
+ njs_int_t ret;
+ njs_str_t str;
+ njs_bool_t is_string;
+ njs_value_t *value;
+ njs_string_t *string;
+ njs_flathsh_t *values_hash;
+ njs_object_prop_t *pr;
+ njs_flathsh_query_t fhq;
is_string = 0;
value_size = sizeof(njs_value_t);
@@ -191,18 +175,18 @@ njs_scope_value_index(njs_vm_t *vm, const njs_value_t *src, njs_uint_t runtime,
start = (u_char *) src;
}
- lhq.key_hash = njs_djb_hash(start, size);
- lhq.key.length = size;
- lhq.key.start = start;
- lhq.proto = &njs_values_hash_proto;
+ fhq.key_hash = njs_djb_hash(start, size);
+ fhq.key.length = size;
+ fhq.key.start = start;
+ fhq.proto = &njs_values_hash_proto;
- if (njs_lvlhsh_find(&vm->shared->values_hash, &lhq) == NJS_OK) {
- value = lhq.value;
+ if (njs_flathsh_find(&vm->shared->values_hash, &fhq) == NJS_OK) {
+ value = ((njs_object_prop_t *) fhq.value)->u.val;
*index = (njs_index_t *) ((u_char *) value + sizeof(njs_value_t));
- } else if (runtime && njs_lvlhsh_find(&vm->values_hash, &lhq) == NJS_OK) {
- value = lhq.value;
+ } else if (runtime && njs_flathsh_find(&vm->values_hash, &fhq) == NJS_OK) {
+ value = ((njs_object_prop_t *) fhq.value)->u.val;
*index = (njs_index_t *) ((u_char *) value + sizeof(njs_value_t));
@@ -243,16 +227,18 @@ njs_scope_value_index(njs_vm_t *vm, const njs_value_t *src, njs_uint_t runtime,
*index = (njs_index_t *) ((u_char *) value + sizeof(njs_value_t));
**index = NJS_INDEX_ERROR;
- lhq.replace = 0;
- lhq.value = value;
- lhq.pool = vm->mem_pool;
+ fhq.replace = 0;
+ fhq.pool = vm->mem_pool;
values_hash = runtime ? &vm->values_hash : &vm->shared->values_hash;
- ret = njs_lvlhsh_insert(values_hash, &lhq);
+ ret = njs_flathsh_insert(values_hash, &fhq);
if (njs_slow_path(ret != NJS_OK)) {
return NULL;
}
+
+ pr = fhq.value;
+ pr->u.val = value;
}
if (start != (u_char *) src) {