Skip to content

Commit b605a4d

Browse files
Removed remnants of level hash.
Level hash has not been compiled since e64a376 (0.8.1) when flat hash was introduced. However, the compatibility layer remained to reduce the diff.
1 parent b46cbce commit b605a4d

34 files changed

+812
-1883
lines changed

auto/make

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ njs_fuzzer: $NJS_BUILD_DIR/njs_auto_config.h \\
301301
lib_test: $NJS_BUILD_DIR/njs_auto_config.h \\
302302
$NJS_BUILD_DIR/random_unit_test \\
303303
$NJS_BUILD_DIR/rbtree_unit_test \\
304-
$NJS_BUILD_DIR/lvlhsh_unit_test \\
304+
$NJS_BUILD_DIR/flathsh_unit_test \\
305305
$NJS_BUILD_DIR/unicode_unit_test
306306

307307
$NJS_BUILD_DIR/random_unit_test
308308
$NJS_BUILD_DIR/rbtree_unit_test
309-
$NJS_BUILD_DIR/lvlhsh_unit_test
309+
$NJS_BUILD_DIR/flathsh_unit_test
310310
$NJS_BUILD_DIR/unicode_unit_test
311311

312312
test262_njs: njs

auto/sources

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ QJS_LIB_SRCS=" \
5757
"
5858

5959
NJS_LIB_TEST_SRCS=" \
60-
src/test/lvlhsh_unit_test.c \
60+
src/test/flathsh_unit_test.c \
6161
src/test/random_unit_test.c \
6262
src/test/rbtree_unit_test.c \
6363
src/test/unicode_unit_test.c \

src/njs_array.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ njs_array_alloc(njs_vm_t *vm, njs_bool_t flat, uint64_t length, uint32_t spare)
8181
}
8282

8383
array->start = array->data;
84-
njs_lvlhsh_init(&array->object.hash);
84+
njs_flathsh_init(&array->object.hash);
8585
array->object.shared_hash = vm->shared->array_instance_hash;
8686
array->object.__proto__ = njs_vm_proto(vm, NJS_OBJ_TYPE_ARRAY);
8787
array->object.slots = NULL;
@@ -1615,13 +1615,13 @@ njs_array_prototype_to_string(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
16151615
{
16161616
njs_int_t ret;
16171617
njs_value_t value;
1618-
njs_flathsh_query_t lhq;
1618+
njs_flathsh_query_t fhq;
16191619

16201620
if (njs_is_object(njs_argument(args, 0))) {
1621-
lhq.proto = &njs_object_hash_proto;
1622-
lhq.key_hash = NJS_ATOM_STRING_join;
1621+
fhq.proto = &njs_object_hash_proto;
1622+
fhq.key_hash = NJS_ATOM_STRING_join;
16231623

1624-
ret = njs_object_property(vm, njs_object(njs_argument(args, 0)), &lhq,
1624+
ret = njs_object_property(vm, njs_object(njs_argument(args, 0)), &fhq,
16251625
&value);
16261626

16271627
if (njs_slow_path(ret == NJS_ERROR)) {

src/njs_array_buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ njs_array_buffer_alloc(njs_vm_t *vm, uint64_t size, njs_bool_t zeroing)
3535

3636
proto = njs_vm_proto(vm, NJS_OBJ_TYPE_ARRAY_BUFFER);
3737

38-
njs_lvlhsh_init(&array->object.hash);
39-
njs_lvlhsh_init(&array->object.shared_hash);
38+
njs_flathsh_init(&array->object.hash);
39+
njs_flathsh_init(&array->object.shared_hash);
4040
array->object.__proto__ = proto;
4141
array->object.slots = NULL;
4242
array->object.type = NJS_ARRAY_BUFFER;

src/njs_atom.c

Lines changed: 63 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <njs_main.h>
99

1010

11-
static njs_int_t njs_lexer_hash_test(njs_lvlhsh_query_t *lhq, void *data);
12-
static njs_int_t njs_atom_hash_test(njs_flathsh_query_t *lhq, void *data);
11+
static njs_int_t njs_lexer_hash_test(njs_flathsh_query_t *fhq, void *data);
12+
static njs_int_t njs_atom_hash_test(njs_flathsh_query_t *fhq, void *data);
1313

1414

1515
const njs_value_t njs_atom[] = {
@@ -33,28 +33,26 @@ const njs_value_t njs_atom[] = {
3333
};
3434

3535

36-
const njs_lvlhsh_proto_t njs_lexer_hash_proto
36+
const njs_flathsh_proto_t njs_lexer_hash_proto
3737
njs_aligned(64) =
3838
{
39-
NJS_LVLHSH_DEFAULT,
4039
njs_lexer_hash_test,
41-
njs_lvlhsh_alloc,
42-
njs_lvlhsh_free,
40+
njs_flathsh_proto_alloc,
41+
njs_flathsh_proto_free,
4342
};
4443

4544

4645
const njs_flathsh_proto_t njs_atom_hash_proto
4746
njs_aligned(64) =
4847
{
49-
0,
5048
njs_atom_hash_test,
51-
njs_lvlhsh_alloc,
52-
njs_lvlhsh_free,
49+
njs_flathsh_proto_alloc,
50+
njs_flathsh_proto_free,
5351
};
5452

5553

5654
static njs_int_t
57-
njs_lexer_hash_test(njs_lvlhsh_query_t *lhq, void *data)
55+
njs_lexer_hash_test(njs_flathsh_query_t *fhq, void *data)
5856
{
5957
u_char *start;
6058
njs_value_t *name;
@@ -63,13 +61,13 @@ njs_lexer_hash_test(njs_lvlhsh_query_t *lhq, void *data)
6361

6462
njs_assert(name->type == NJS_STRING);
6563

66-
if (lhq->key.length != name->string.data->size) {
64+
if (fhq->key.length != name->string.data->size) {
6765
return NJS_DECLINED;
6866
}
6967

7068
start = name->string.data->start;
7169

72-
if (memcmp(start, lhq->key.start, lhq->key.length) == 0) {
70+
if (memcmp(start, fhq->key.start, fhq->key.length) == 0) {
7371
return NJS_OK;
7472
}
7573

@@ -81,33 +79,33 @@ njs_value_t *
8179
njs_atom_find_or_add(njs_vm_t *vm, u_char *key, size_t size, size_t length,
8280
uint32_t hash)
8381
{
84-
njs_int_t ret;
85-
njs_object_prop_t *prop;
86-
njs_lvlhsh_query_t lhq;
82+
njs_int_t ret;
83+
njs_object_prop_t *prop;
84+
njs_flathsh_query_t fhq;
8785

88-
lhq.key.start = key;
89-
lhq.key.length = size;
90-
lhq.key_hash = hash;
91-
lhq.proto = &njs_lexer_hash_proto;
86+
fhq.key.start = key;
87+
fhq.key.length = size;
88+
fhq.key_hash = hash;
89+
fhq.proto = &njs_lexer_hash_proto;
9290

93-
ret = njs_lvlhsh_find(vm->atom_hash_current, &lhq);
91+
ret = njs_flathsh_find(vm->atom_hash_current, &fhq);
9492
if (ret == NJS_OK) {
95-
return njs_prop_value(lhq.value);
93+
return njs_prop_value(fhq.value);
9694
}
9795

98-
ret = njs_lvlhsh_find(&vm->atom_hash_shared, &lhq);
96+
ret = njs_flathsh_find(&vm->atom_hash_shared, &fhq);
9997
if (ret == NJS_OK) {
100-
return njs_prop_value(lhq.value);
98+
return njs_prop_value(fhq.value);
10199
}
102100

103-
lhq.pool = vm->mem_pool;
101+
fhq.pool = vm->mem_pool;
104102

105-
ret = njs_lvlhsh_insert(vm->atom_hash_current, &lhq);
103+
ret = njs_flathsh_insert(vm->atom_hash_current, &fhq);
106104
if (njs_slow_path(ret != NJS_OK)) {
107105
return NULL;
108106
}
109107

110-
prop = lhq.value;
108+
prop = fhq.value;
111109

112110
ret = njs_string_create(vm, &prop->u.value, key, size);
113111
if (njs_slow_path(ret != NJS_OK)) {
@@ -130,35 +128,35 @@ static njs_value_t *
130128
njs_atom_find_or_add_string(njs_vm_t *vm, njs_value_t *value,
131129
uint32_t hash)
132130
{
133-
njs_int_t ret;
134-
njs_object_prop_t *prop;
135-
njs_lvlhsh_query_t lhq;
131+
njs_int_t ret;
132+
njs_object_prop_t *prop;
133+
njs_flathsh_query_t fhq;
136134

137135
njs_assert(njs_is_string(value));
138136

139-
lhq.key.start = value->string.data->start;
140-
lhq.key.length = value->string.data->size;
141-
lhq.key_hash = hash;
142-
lhq.proto = &njs_lexer_hash_proto;
137+
fhq.key.start = value->string.data->start;
138+
fhq.key.length = value->string.data->size;
139+
fhq.key_hash = hash;
140+
fhq.proto = &njs_lexer_hash_proto;
143141

144-
ret = njs_lvlhsh_find(vm->atom_hash_current, &lhq);
142+
ret = njs_flathsh_find(vm->atom_hash_current, &fhq);
145143
if (ret == NJS_OK) {
146-
return njs_prop_value(lhq.value);
144+
return njs_prop_value(fhq.value);
147145
}
148146

149-
ret = njs_lvlhsh_find(&vm->atom_hash_shared, &lhq);
147+
ret = njs_flathsh_find(&vm->atom_hash_shared, &fhq);
150148
if (ret == NJS_OK) {
151-
return njs_prop_value(lhq.value);
149+
return njs_prop_value(fhq.value);;
152150
}
153151

154-
lhq.pool = vm->mem_pool;
152+
fhq.pool = vm->mem_pool;
155153

156-
ret = njs_lvlhsh_insert(vm->atom_hash_current, &lhq);
154+
ret = njs_flathsh_insert(vm->atom_hash_current, &fhq);
157155
if (njs_slow_path(ret != NJS_OK)) {
158156
return NULL;
159157
}
160158

161-
prop = lhq.value;
159+
prop = fhq.value;
162160

163161
prop->u.value = *value;
164162

@@ -175,7 +173,7 @@ njs_atom_find_or_add_string(njs_vm_t *vm, njs_value_t *value,
175173

176174

177175
static njs_int_t
178-
njs_atom_hash_test(njs_flathsh_query_t *lhq, void *data)
176+
njs_atom_hash_test(njs_flathsh_query_t *fhq, void *data)
179177
{
180178
size_t size;
181179
u_char *start;
@@ -184,25 +182,25 @@ njs_atom_hash_test(njs_flathsh_query_t *lhq, void *data)
184182
name = data;
185183

186184
if (name->type == NJS_STRING
187-
&& ((njs_value_t *) lhq->value)->type == NJS_STRING)
185+
&& ((njs_value_t *) fhq->value)->type == NJS_STRING)
188186
{
189187
size = name->string.data->length;
190188

191-
if (lhq->key.length != size) {
189+
if (fhq->key.length != size) {
192190
return NJS_DECLINED;
193191
}
194192

195193
start = (u_char *) name->string.data->start;
196194

197-
if (memcmp(start, lhq->key.start, lhq->key.length) == 0) {
195+
if (memcmp(start, fhq->key.start, fhq->key.length) == 0) {
198196
return NJS_OK;
199197
}
200198
}
201199

202200
if (name->type == NJS_SYMBOL
203-
&& ((njs_value_t *) lhq->value)->type == NJS_SYMBOL)
201+
&& ((njs_value_t *) fhq->value)->type == NJS_SYMBOL)
204202
{
205-
if (lhq->key_hash == name->atom_id) {
203+
if (fhq->key_hash == name->atom_id) {
206204
return NJS_OK;
207205
}
208206
}
@@ -219,23 +217,23 @@ njs_atom_hash_init(njs_vm_t *vm)
219217
njs_int_t ret;
220218
njs_uint_t n;
221219
const njs_value_t *value, *values;
222-
njs_flathsh_query_t lhq;
220+
njs_flathsh_query_t fhq;
223221

224222
values = &njs_atom[0];
225223

226-
njs_lvlhsh_init(&vm->atom_hash_shared);
224+
njs_flathsh_init(&vm->atom_hash_shared);
227225

228-
lhq.replace = 0;
229-
lhq.proto = &njs_atom_hash_proto;
230-
lhq.pool = vm->mem_pool;
226+
fhq.replace = 0;
227+
fhq.proto = &njs_atom_hash_proto;
228+
fhq.pool = vm->mem_pool;
231229

232230
for (n = 0; n < NJS_ATOM_SIZE; n++) {
233231
value = &values[n];
234232

235233
if (value->type == NJS_SYMBOL) {
236-
lhq.key_hash = value->string.atom_id;
234+
fhq.key_hash = value->string.atom_id;
237235

238-
ret = njs_flathsh_insert(&vm->atom_hash_shared, &lhq);
236+
ret = njs_flathsh_insert(&vm->atom_hash_shared, &fhq);
239237
if (njs_slow_path(ret != NJS_OK)) {
240238
njs_internal_error(vm, "flathsh insert/replace failed");
241239
return 0xffffffff;
@@ -246,18 +244,18 @@ njs_atom_hash_init(njs_vm_t *vm)
246244
start = value->string.data->start;
247245
len = value->string.data->length;
248246

249-
lhq.key_hash = njs_djb_hash(start, len);
250-
lhq.key.length = len;
251-
lhq.key.start = start;
247+
fhq.key_hash = njs_djb_hash(start, len);
248+
fhq.key.length = len;
249+
fhq.key.start = start;
252250

253-
ret = njs_flathsh_insert(&vm->atom_hash_shared, &lhq);
251+
ret = njs_flathsh_insert(&vm->atom_hash_shared, &fhq);
254252
if (njs_slow_path(ret != NJS_OK)) {
255253
njs_internal_error(vm, "flathsh insert/replace failed");
256254
return 0xffffffff;
257255
}
258256
}
259257

260-
*njs_prop_value(lhq.value) = *value;
258+
*njs_prop_value(fhq.value) = *value;
261259
}
262260

263261
vm->atom_hash_current = &vm->atom_hash_shared;
@@ -349,26 +347,26 @@ njs_int_t
349347
njs_atom_symbol_add(njs_vm_t *vm, njs_value_t *value)
350348
{
351349
njs_int_t ret;
352-
njs_flathsh_query_t lhq;
350+
njs_flathsh_query_t fhq;
353351

354352
njs_assert(value->atom_id == NJS_ATOM_STRING_unknown);
355353

356-
lhq.replace = 0;
357-
lhq.proto = &njs_lexer_hash_proto;
358-
lhq.pool = vm->mem_pool;
354+
fhq.replace = 0;
355+
fhq.proto = &njs_lexer_hash_proto;
356+
fhq.pool = vm->mem_pool;
359357

360358
value->atom_id = vm->atom_id_generator++;
361359

362360
if (value->type == NJS_SYMBOL) {
363-
lhq.key_hash = value->atom_id;
361+
fhq.key_hash = value->atom_id;
364362

365-
ret = njs_flathsh_insert(vm->atom_hash_current, &lhq);
363+
ret = njs_flathsh_insert(vm->atom_hash_current, &fhq);
366364
if (njs_slow_path(ret != NJS_OK)) {
367365
njs_internal_error(vm, "flathsh insert/replace failed");
368366
return NJS_ERROR;
369367
}
370368

371-
*njs_prop_value(lhq.value) = *value;
369+
*njs_prop_value(fhq.value) = *value;
372370
}
373371

374372
return NJS_OK;

src/njs_buffer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ njs_buffer_set(njs_vm_t *vm, njs_value_t *value, const u_char *start,
156156

157157
proto = njs_vm_proto(vm, NJS_OBJ_TYPE_ARRAY_BUFFER);
158158

159-
njs_lvlhsh_init(&buffer->object.hash);
160-
njs_lvlhsh_init(&buffer->object.shared_hash);
159+
njs_flathsh_init(&buffer->object.hash);
160+
njs_flathsh_init(&buffer->object.shared_hash);
161161
buffer->object.__proto__ = proto;
162162
buffer->object.slots = NULL;
163163
buffer->object.type = NJS_ARRAY_BUFFER;
@@ -171,8 +171,8 @@ njs_buffer_set(njs_vm_t *vm, njs_value_t *value, const u_char *start,
171171
proto = njs_vm_proto(vm, NJS_OBJ_TYPE_BUFFER);
172172

173173
array->type = NJS_OBJ_TYPE_UINT8_ARRAY;
174-
njs_lvlhsh_init(&array->object.hash);
175-
njs_lvlhsh_init(&array->object.shared_hash);
174+
njs_flathsh_init(&array->object.hash);
175+
njs_flathsh_init(&array->object.shared_hash);
176176
array->object.__proto__ = proto;
177177
array->object.slots = NULL;
178178
array->object.type = NJS_TYPED_ARRAY;

0 commit comments

Comments
 (0)