From: Igor Sysoev Date: Fri, 30 Oct 2015 13:22:29 +0000 (+0300) Subject: nxt_vector interface was renamed to nxt_array. X-Git-Tag: 0.1.0~127 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=2a5a3c3861c380dd48c13014b2c09cf005872077;p=njs.git nxt_vector interface was renamed to nxt_array. --- diff --git a/njs/njs_generator.c b/njs/njs_generator.c index e6c3c6e3..62f095be 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -1935,14 +1935,14 @@ njs_generator_dest_index(njs_vm_t *vm, njs_parser_t *parser, static njs_index_t njs_generator_temp_index_get(njs_parser_t *parser) { - nxt_uint_t n; - njs_index_t index, *last; - nxt_vector_t *cache; + nxt_uint_t n; + njs_index_t index, *last; + nxt_array_t *cache; cache = parser->index_cache; if (cache != NULL && cache->items != 0) { - last = nxt_vector_remove_last(cache); + last = nxt_array_remove_last(cache); nxt_thread_log_debug("CACHE %p", *last); @@ -1994,15 +1994,15 @@ static nxt_int_t njs_generator_index_release(njs_vm_t *vm, njs_parser_t *parser, njs_index_t index) { - njs_index_t *last; - nxt_vector_t *cache; + njs_index_t *last; + nxt_array_t *cache; nxt_thread_log_debug("RELEASE %p", index); cache = parser->index_cache; if (cache == NULL) { - cache = nxt_vector_create(4, sizeof(njs_value_t *), &njs_array_mem_proto, + cache = nxt_array_create(4, sizeof(njs_value_t *), &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_slow_path(cache == NULL)) { return NXT_ERROR; @@ -2011,7 +2011,7 @@ njs_generator_index_release(njs_vm_t *vm, njs_parser_t *parser, parser->index_cache = cache; } - last = nxt_vector_add(cache, &njs_array_mem_proto, vm->mem_cache_pool); + last = nxt_array_add(cache, &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_fast_path(last != NULL)) { *last = index; return NXT_OK; diff --git a/njs/njs_parser.c b/njs/njs_parser.c index 01a27f25..1c961783 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -290,8 +290,8 @@ njs_parser_function_statement(njs_vm_t *vm, njs_parser_t *parser) } else { /* Anonymous function. */ - value = nxt_vector_add(parser->scope_values, &njs_array_mem_proto, - vm->mem_cache_pool); + value = nxt_array_add(parser->scope_values, &njs_array_mem_proto, + vm->mem_cache_pool); if (nxt_slow_path(value == NULL)) { return NJS_TOKEN_ERROR; } @@ -325,7 +325,7 @@ njs_parser_function_statement(njs_vm_t *vm, njs_parser_t *parser) /* njs_return() size. */ fn_parser->code_size = sizeof(njs_vmcode_stop_t); - fn_parser->arguments = nxt_vector_create(4, sizeof(njs_variable_t), + fn_parser->arguments = nxt_array_create(4, sizeof(njs_variable_t), &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_slow_path(fn_parser->arguments == NULL)) { @@ -351,7 +351,7 @@ njs_parser_function_statement(njs_vm_t *vm, njs_parser_t *parser) nxt_thread_log_debug("arg: %V", name); - arg = nxt_vector_add(fn_parser->arguments, &njs_array_mem_proto, + arg = nxt_array_add(fn_parser->arguments, &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_slow_path(arg == NULL)) { return NJS_TOKEN_ERROR; @@ -394,7 +394,7 @@ njs_parser_function_statement(njs_vm_t *vm, njs_parser_t *parser) return NJS_TOKEN_ERROR; } - fn_parser->scope_values = nxt_vector_create(4, sizeof(njs_value_t), + fn_parser->scope_values = nxt_array_create(4, sizeof(njs_value_t), &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_slow_path(fn_parser->scope_values == NULL)) { @@ -481,7 +481,7 @@ njs_parser_function_expression(njs_vm_t *vm, njs_parser_t *parser) /* njs_return() size. */ fn_parser->code_size = sizeof(njs_vmcode_stop_t); - fn_parser->arguments = nxt_vector_create(4, sizeof(njs_variable_t), + fn_parser->arguments = nxt_array_create(4, sizeof(njs_variable_t), &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_slow_path(fn_parser->arguments == NULL)) { @@ -507,7 +507,7 @@ njs_parser_function_expression(njs_vm_t *vm, njs_parser_t *parser) nxt_thread_log_debug("arg: %V", name); - arg = nxt_vector_add(fn_parser->arguments, &njs_array_mem_proto, + arg = nxt_array_add(fn_parser->arguments, &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_slow_path(arg == NULL)) { return NJS_TOKEN_ERROR; @@ -549,7 +549,7 @@ njs_parser_function_expression(njs_vm_t *vm, njs_parser_t *parser) return NJS_TOKEN_ERROR; } - fn_parser->scope_values = nxt_vector_create(4, sizeof(njs_value_t), + fn_parser->scope_values = nxt_array_create(4, sizeof(njs_value_t), &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_slow_path(fn_parser->scope_values == NULL)) { diff --git a/njs/njs_parser.h b/njs/njs_parser.h index ab07e958..2cfe2a17 100644 --- a/njs/njs_parser.h +++ b/njs/njs_parser.h @@ -238,16 +238,16 @@ struct njs_parser_s { njs_parser_node_t *node; /* Vector of njs_variable_t. */ - nxt_vector_t *arguments; + nxt_array_t *arguments; nxt_lvlhsh_t variables_hash; nxt_lvlhsh_t values_hash; nxt_lvlhsh_t functions_hash; - nxt_vector_t *index_cache; + nxt_array_t *index_cache; njs_index_t index[NJS_SCOPES - NJS_INDEX_CACHE]; - nxt_vector_t *scope_values; + nxt_array_t *scope_values; uint8_t scope; /* 4 bits */ uint8_t branch; /* 1 bit */ diff --git a/njs/njs_variable.c b/njs/njs_variable.c index 0d2c06b7..d0cb758b 100644 --- a/njs/njs_variable.c +++ b/njs/njs_variable.c @@ -136,7 +136,7 @@ njs_variable_alloc(njs_vm_t *vm, njs_parser_t *parser, nxt_str_t *name) memcpy(var->name_start, name->data, name->len); var->name_len = name->len; - value = nxt_vector_add(parser->scope_values, &njs_array_mem_proto, + value = nxt_array_add(parser->scope_values, &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_fast_path(value != NULL)) { *value = njs_value_void; diff --git a/njs/njscript.c b/njs/njscript.c index b8d2c79a..e3eed18d 100644 --- a/njs/njscript.c +++ b/njs/njscript.c @@ -228,15 +228,15 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end) parser->scope_offset = NJS_INDEX_GLOBAL_OFFSET; parser->index[NJS_SCOPE_GLOBAL - NJS_INDEX_CACHE] = NJS_INDEX_GLOBAL_OFFSET; - parser->scope_values = nxt_vector_create(4, sizeof(njs_value_t), + parser->scope_values = nxt_array_create(4, sizeof(njs_value_t), &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_slow_path(parser->scope_values == NULL)) { return NJS_ERROR; } - /* Empty vector to minimize tests in njs_parser_variable(). */ - parser->arguments = nxt_vector_create(0, sizeof(njs_variable_t), + /* Empty array to minimize tests in njs_parser_variable(). */ + parser->arguments = nxt_array_create(0, sizeof(njs_variable_t), &njs_array_mem_proto, vm->mem_cache_pool); if (nxt_slow_path(parser->arguments == NULL)) { diff --git a/nxt/nxt_array.c b/nxt/nxt_array.c index 7d19acc1..222cd0e3 100644 --- a/nxt/nxt_array.c +++ b/nxt/nxt_array.c @@ -11,129 +11,127 @@ #include -nxt_vector_t * -nxt_vector_create(nxt_uint_t items, size_t item_size, +nxt_array_t * +nxt_array_create(nxt_uint_t items, size_t item_size, const nxt_mem_proto_t *proto, void *pool) { - nxt_vector_t *vector; + nxt_array_t *array; - vector = proto->alloc(pool, sizeof(nxt_vector_t) + items * item_size); + array = proto->alloc(pool, sizeof(nxt_array_t) + items * item_size); - if (nxt_fast_path(vector != NULL)) { - vector->start = (char *) vector + sizeof(nxt_vector_t); - vector->items = 0; - vector->item_size = item_size; - vector->avalaible = items; - vector->type = NXT_VECTOR_EMBEDDED; + if (nxt_fast_path(array != NULL)) { + array->start = (char *) array + sizeof(nxt_array_t); + array->items = 0; + array->item_size = item_size; + array->avalaible = items; + array->type = NXT_ARRAY_EMBEDDED; } - return vector; + return array; } void * -nxt_vector_init(nxt_vector_t *vector, nxt_uint_t items, size_t item_size, +nxt_array_init(nxt_array_t *array, nxt_uint_t items, size_t item_size, const nxt_mem_proto_t *proto, void *pool) { - vector->start = proto->alloc(pool, items * item_size); + array->start = proto->alloc(pool, items * item_size); - if (nxt_fast_path(vector->start != NULL)) { - vector->items = 0; - vector->item_size = item_size; - vector->avalaible = items; - vector->type = NXT_VECTOR_INITED; + if (nxt_fast_path(array->start != NULL)) { + array->items = 0; + array->item_size = item_size; + array->avalaible = items; + array->type = NXT_ARRAY_INITED; } - return vector->start; + return array->start; } void -nxt_vector_destroy(nxt_vector_t *vector, const nxt_mem_proto_t *proto, - void *pool) +nxt_array_destroy(nxt_array_t *array, const nxt_mem_proto_t *proto, void *pool) { - switch (vector->type) { + switch (array->type) { - case NXT_VECTOR_INITED: - proto->free(pool, vector->start); + case NXT_ARRAY_INITED: + proto->free(pool, array->start); #if (NXT_DEBUG) - vector->start = NULL; - vector->items = 0; - vector->avalaible = 0; + array->start = NULL; + array->items = 0; + array->avalaible = 0; #endif break; - case NXT_VECTOR_DESCRETE: - proto->free(pool, vector->start); + case NXT_ARRAY_DESCRETE: + proto->free(pool, array->start); /* Fall through. */ - case NXT_VECTOR_EMBEDDED: - proto->free(pool, vector); + case NXT_ARRAY_EMBEDDED: + proto->free(pool, array); break; } } void * -nxt_vector_add(nxt_vector_t *vector, const nxt_mem_proto_t *proto, void *pool) +nxt_array_add(nxt_array_t *array, const nxt_mem_proto_t *proto, void *pool) { void *item, *start, *old; size_t size; uint32_t n; - n = vector->avalaible; + n = array->avalaible; - if (n == vector->items) { + if (n == array->items) { if (n < 16) { - /* Allocate new vector twice as much as current. */ + /* Allocate new array twice as much as current. */ n *= 2; } else { - /* Allocate new vector half as much as current. */ + /* Allocate new array half as much as current. */ n += n / 2; } - size = n * vector->item_size; + size = n * array->item_size; start = proto->alloc(pool, size); if (nxt_slow_path(start == NULL)) { return NULL; } - vector->avalaible = n; - old = vector->start; - vector->start = start; + array->avalaible = n; + old = array->start; + array->start = start; memcpy(start, old, size); - if (vector->type == NXT_VECTOR_EMBEDDED) { - vector->type = NXT_VECTOR_DESCRETE; + if (array->type == NXT_ARRAY_EMBEDDED) { + array->type = NXT_ARRAY_DESCRETE; } else { proto->free(pool, old); } } - item = (char *) vector->start + vector->item_size * vector->items; + item = (char *) array->start + array->item_size * array->items; - vector->items++; + array->items++; return item; } void * -nxt_vector_zero_add(nxt_vector_t *vector, const nxt_mem_proto_t *proto, - void *pool) +nxt_array_zero_add(nxt_array_t *array, const nxt_mem_proto_t *proto, void *pool) { void *item; - item = nxt_vector_add(vector, proto, pool); + item = nxt_array_add(array, proto, pool); if (nxt_fast_path(item != NULL)) { - memset(item, 0, vector->item_size); + memset(item, 0, array->item_size); } return item; @@ -141,13 +139,13 @@ nxt_vector_zero_add(nxt_vector_t *vector, const nxt_mem_proto_t *proto, void -nxt_vector_remove(nxt_vector_t *vector, void *item) +nxt_array_remove(nxt_array_t *array, void *item) { u_char *next, *last, *end; uint32_t item_size; - item_size = vector->item_size; - end = (u_char *) vector->start + item_size * vector->items; + item_size = array->item_size; + end = (u_char *) array->start + item_size * array->items; last = end - item_size; if (item != last) { @@ -156,5 +154,5 @@ nxt_vector_remove(nxt_vector_t *vector, void *item) memmove(item, next, end - next); } - vector->items--; + array->items--; } diff --git a/nxt/nxt_array.h b/nxt/nxt_array.h index f12ce469..5685f110 100644 --- a/nxt/nxt_array.h +++ b/nxt/nxt_array.h @@ -9,57 +9,57 @@ typedef enum { - NXT_VECTOR_INITED = 0, - NXT_VECTOR_DESCRETE, - NXT_VECTOR_EMBEDDED, -} nxt_vector_type_t; + NXT_ARRAY_INITED = 0, + NXT_ARRAY_DESCRETE, + NXT_ARRAY_EMBEDDED, +} nxt_array_type_t; typedef struct { void *start; /* - * A vector can hold no more than 65536 items. + * A array can hold no more than 65536 items. * The item size is no more than 64K. */ uint16_t items; uint16_t avalaible; uint16_t item_size; - nxt_vector_type_t type:8; -} nxt_vector_t; + nxt_array_type_t type:8; +} nxt_array_t; -NXT_EXPORT nxt_vector_t *nxt_vector_create(nxt_uint_t items, size_t item_size, +NXT_EXPORT nxt_array_t *nxt_array_create(nxt_uint_t items, size_t item_size, const nxt_mem_proto_t *proto, void *pool); -NXT_EXPORT void *nxt_vector_init(nxt_vector_t *vector, nxt_uint_t items, +NXT_EXPORT void *nxt_array_init(nxt_array_t *array, nxt_uint_t items, size_t item_size, const nxt_mem_proto_t *proto, void *pool); -NXT_EXPORT void nxt_vector_destroy(nxt_vector_t *vector, +NXT_EXPORT void nxt_array_destroy(nxt_array_t *array, const nxt_mem_proto_t *proto, void *pool); -NXT_EXPORT void *nxt_vector_add(nxt_vector_t *vector, +NXT_EXPORT void *nxt_array_add(nxt_array_t *array, const nxt_mem_proto_t *proto, + void *pool); +NXT_EXPORT void *nxt_array_zero_add(nxt_array_t *array, const nxt_mem_proto_t *proto, void *pool); -NXT_EXPORT void *nxt_vector_zero_add(nxt_vector_t *vector, - const nxt_mem_proto_t *proto, void *pool); -NXT_EXPORT void nxt_vector_remove(nxt_vector_t *vector, void *item); +NXT_EXPORT void nxt_array_remove(nxt_array_t *array, void *item); -#define nxt_vector_last(vector) \ +#define nxt_array_last(array) \ ((void *) \ - ((char *) (vector)->start \ - + (vector)->item_size * ((vector)->items - 1))) + ((char *) (array)->start \ + + (array)->item_size * ((array)->items - 1))) -#define nxt_vector_reset(vector) \ - (vector)->items = 0; +#define nxt_array_reset(array) \ + (array)->items = 0; -#define nxt_vector_is_empty(vector) \ - ((vector)->items == 0) +#define nxt_array_is_empty(array) \ + ((array)->items == 0) nxt_inline void * -nxt_vector_remove_last(nxt_vector_t *vector) +nxt_array_remove_last(nxt_array_t *array) { - vector->items--; - return (char *) vector->start + vector->item_size * vector->items; + array->items--; + return (char *) array->start + array->item_size * array->items; }