]> git.kaiwu.me - njs.git/commitdiff
nxt_vector interface was renamed to nxt_array.
authorIgor Sysoev <igor@sysoev.ru>
Fri, 30 Oct 2015 13:22:29 +0000 (16:22 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 30 Oct 2015 13:22:29 +0000 (16:22 +0300)
njs/njs_generator.c
njs/njs_parser.c
njs/njs_parser.h
njs/njs_variable.c
njs/njscript.c
nxt/nxt_array.c
nxt/nxt_array.h

index e6c3c6e3403723c386631a4f87301c0ff33489a2..62f095bedb1d77db0cf9805feb3bd4ca3171268b 100644 (file)
@@ -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;
index 01a27f25f4f50d914d3d2b079830b8582bec6efb..1c961783d421cd5831c722754b7c1fbd5a09601d 100644 (file)
@@ -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)) {
index ab07e958f8b27ef7e24f24f499b6e6deaa2c2b05..2cfe2a171f577f67b0044d77ac0c12ba881aa0d7 100644 (file)
@@ -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 */
index 0d2c06b716c00af374c509464e1db04be57c01d3..d0cb758bd7b342be8f7e292c0e71bfa04a9920e5 100644 (file)
@@ -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;
index b8d2c79af559bd3100b17af27e09755ac5ac725d..e3eed18d39a674a36923ee8a7087104e46e0abe2 100644 (file)
@@ -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)) {
index 7d19acc1d7892acd442fbaf4b9367c7ecd759c9e..222cd0e3274a2677ae109a842da76b906edd256e 100644 (file)
 #include <string.h>
 
 
-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--;
 }
index f12ce469fbe8c482dd0c56754645646a72c783a1..5685f110178dbc82e18362a5e541a0f6397ca96f 100644 (file)
@@ -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;
 }