Skip to content

Commit 3810cb3

Browse files
Inline optimizations.
1 parent 457909e commit 3810cb3

File tree

10 files changed

+522
-359
lines changed

10 files changed

+522
-359
lines changed

src/njs_atom.c

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -136,88 +136,3 @@ njs_atom_hash_init()
136136

137137
return;
138138
};
139-
140-
141-
/*
142-
* value is always key: string or number or symbol.
143-
*
144-
* symbol always contians atom_id by construction. do nothing;
145-
* number if short number it is atomized by "| 0x80000000";
146-
* string if represents short number it is atomized by "| 0x80000000";
147-
*
148-
* for string and symbol atom_ids common range is uint32_t < 0x80000000.
149-
*/
150-
151-
njs_int_t
152-
njs_atom_atomize_key(njs_vm_t *vm, njs_value_t *value)
153-
{
154-
double num;
155-
uint32_t hash_id;
156-
njs_int_t ret;
157-
njs_value_t val_str;
158-
const njs_value_t *entry;
159-
160-
switch (value->type) {
161-
case NJS_STRING:
162-
num = njs_key_to_index(value);
163-
if (njs_fast_path(njs_key_is_integer_index(num, value)) &&
164-
((uint32_t) num) < 0x80000000)
165-
{
166-
value->atom_id = ((uint32_t) num) | 0x80000000;
167-
168-
} else {
169-
hash_id = njs_djb_hash(value->string.data->start,
170-
value->string.data->size);
171-
172-
entry = njs_lexer_keyword_find(vm, value->string.data->start,
173-
value->string.data->size,
174-
value->string.data->length,
175-
hash_id);
176-
if (njs_slow_path(entry == NULL)) {
177-
return NJS_ERROR;
178-
}
179-
180-
/* TODO: if (<<value is string>>) <<try release>>(string) */
181-
*value = *entry;
182-
}
183-
break;
184-
185-
case NJS_NUMBER:
186-
num = value->data.u.number;
187-
if (njs_fast_path(njs_key_is_integer_index(num, value)) &&
188-
((uint32_t) num) < 0x80000000)
189-
{
190-
value->atom_id = ((uint32_t) num) | 0x80000000;
191-
192-
} else {
193-
/* convert num to string, and atomize it. */
194-
ret = njs_number_to_string(vm, &val_str, value);
195-
if (ret != NJS_OK) {
196-
return ret;
197-
}
198-
199-
if (val_str.atom_id == 0) {
200-
hash_id = njs_djb_hash(val_str.string.data->start,
201-
val_str.string.data->size);
202-
203-
entry = njs_lexer_keyword_find(vm, val_str.string.data->start,
204-
val_str.string.data->size,
205-
val_str.string.data->length,
206-
hash_id);
207-
if (njs_slow_path(entry == NULL)) {
208-
return NJS_ERROR;
209-
}
210-
211-
value->atom_id = entry->atom_id;
212-
213-
} else {
214-
value->atom_id = val_str.atom_id;
215-
}
216-
}
217-
break;
218-
default:
219-
/* NJS_SYMBOL: do nothing. */
220-
}
221-
222-
return NJS_OK;
223-
}

src/njs_atom.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ typedef struct {
3131

3232

3333
void njs_atom_hash_init(void);
34-
njs_int_t njs_atom_atomize_key(njs_vm_t *vm, njs_value_t *value);
3534

3635

3736
extern njs_atom_values_t njs_atom;

src/njs_flathsh.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,9 @@
7676
#define NJS_FLATHSH_ELTS_MINIMUM_TO_SHRINK 8
7777

7878

79-
struct njs_flathsh_descr_s {
80-
uint32_t hash_mask;
81-
uint32_t elts_size; /* allocated properties */
82-
uint32_t elts_count; /* include deleted properties */
83-
uint32_t elts_deleted_count;
84-
};
85-
86-
8779
static njs_flathsh_descr_t *njs_flathsh_alloc(njs_flathsh_query_t *fhq,
8880
size_t hash_size, size_t elts_size);
89-
static njs_flathsh_descr_t *njs_expand_elts(njs_flathsh_query_t *fhq,
81+
njs_flathsh_descr_t *njs_expand_elts(njs_flathsh_query_t *fhq,
9082
njs_flathsh_descr_t *h);
9183

9284

@@ -130,27 +122,13 @@ njs_flathsh_descr(void *chunk, size_t hash_size)
130122
}
131123

132124

133-
njs_inline uint32_t *
134-
njs_hash_cells_end(njs_flathsh_descr_t *h)
135-
{
136-
return (uint32_t *) h;
137-
}
138-
139-
140125
njs_inline void *
141126
njs_flathsh_chunk(njs_flathsh_descr_t *h)
142127
{
143128
return njs_hash_cells_end(h) - ((njs_int_t) h->hash_mask + 1);
144129
}
145130

146131

147-
njs_inline njs_flathsh_elt_t *
148-
njs_hash_elts(njs_flathsh_descr_t *h)
149-
{
150-
return (njs_flathsh_elt_t *) ((char *) h + sizeof(njs_flathsh_descr_t));
151-
}
152-
153-
154132
/*
155133
* Create a new empty flat hash.
156134
*/
@@ -236,7 +214,7 @@ njs_flathsh_add_elt(njs_flathsh_t *fh, njs_flathsh_query_t *fhq)
236214
}
237215

238216

239-
static njs_flathsh_descr_t *
217+
njs_flathsh_descr_t *
240218
njs_expand_elts(njs_flathsh_query_t *fhq, njs_flathsh_descr_t *h)
241219
{
242220
void *chunk;

src/njs_flathsh.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ typedef void (*njs_flathsh_free_t)(void *ctx, void *p, size_t size);
2929
typedef struct njs_flathsh_proto_s njs_flathsh_proto_t;
3030

3131

32+
struct njs_flathsh_descr_s {
33+
uint32_t hash_mask;
34+
uint32_t elts_size; /* allocated properties */
35+
uint32_t elts_count; /* include deleted properties */
36+
uint32_t elts_deleted_count;
37+
};
38+
39+
3240
struct njs_flathsh_proto_s {
3341
uint32_t not_used;
3442
njs_flathsh_test_t test;
@@ -64,6 +72,20 @@ struct njs_flathsh_query_s {
6472
((fhl)->slot == (fhr)->slot)
6573

6674

75+
njs_inline uint32_t *
76+
njs_hash_cells_end(njs_flathsh_descr_t *h)
77+
{
78+
return (uint32_t *) h;
79+
}
80+
81+
82+
njs_inline njs_flathsh_elt_t *
83+
njs_hash_elts(njs_flathsh_descr_t *h)
84+
{
85+
return (njs_flathsh_elt_t *) ((char *) h + sizeof(njs_flathsh_descr_t));
86+
}
87+
88+
6789
/*
6890
* njs_flathsh_find() finds a hash element. If the element has been
6991
* found then it is stored in the fhq->value and njs_flathsh_find()
@@ -128,6 +150,8 @@ NJS_EXPORT njs_flathsh_elt_t *njs_flathsh_add_elt(njs_flathsh_t *fh,
128150

129151
NJS_EXPORT njs_flathsh_descr_t *njs_flathsh_new(njs_flathsh_query_t *fhq);
130152
NJS_EXPORT void njs_flathsh_destroy(njs_flathsh_t *fh, njs_flathsh_query_t *fhq);
153+
NJS_EXPORT njs_flathsh_descr_t * njs_expand_elts(njs_flathsh_query_t *fhq,
154+
njs_flathsh_descr_t *h);
131155

132156
NJS_EXPORT njs_int_t njs_flathsh_alloc_copy(njs_mp_t *mp, njs_flathsh_t *to,
133157
njs_flathsh_t *from);

0 commit comments

Comments
 (0)