]> git.kaiwu.me - njs.git/commitdiff
Style and small miscellaneous fixes.
authorIgor Sysoev <igor@sysoev.ru>
Fri, 23 Sep 2016 08:59:56 +0000 (11:59 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 23 Sep 2016 08:59:56 +0000 (11:59 +0300)
njs/njs_builtin.c
njs/njs_function.h
njs/njs_regexp.c
njs/njs_regexp_pattern.h
njs/njs_vm.c
njs/njs_vm.h
njs/test/njs_unit_test.c
nxt/nxt_mem_cache_pool.c
nxt/nxt_types.h
nxt/test/lvlhsh_unit_test.c
nxt/test/utf8_unit_test.c

index c493ca88132dd71a890860d7327aa570417d6f16..23af28ac179e5419f2e03f1aa5cd9ad24ecff501 100644 (file)
@@ -43,7 +43,7 @@ njs_builtin_objects_create(njs_vm_t *vm)
     njs_function_t          *functions, *constructors;
     njs_object_prototype_t  *prototypes;
 
-    static const njs_object_init_t    *prototype_init[] = {
+    static const njs_object_init_t  *prototype_init[] = {
         &njs_object_prototype_init,
         &njs_array_prototype_init,
         &njs_boolean_prototype_init,
@@ -56,7 +56,7 @@ njs_builtin_objects_create(njs_vm_t *vm)
 
     static const njs_object_prototype_t  prototype_values[] = {
         /*
-         * GCC 4 complains about unitialized .shared field,
+         * GCC 4 complains about uninitialized .shared field,
          * if the .type field is initialized as .object.type.
          */
         { .object =       { .type = NJS_OBJECT } },
@@ -95,15 +95,15 @@ njs_builtin_objects_create(njs_vm_t *vm)
 
     static const njs_function_init_t  native_constructors[] = {
         /* SunC does not allow empty array initialization. */
-        { njs_object_constructor,   { 0 } },
-        { njs_array_constructor,    { 0 } },
-        { njs_boolean_constructor,  { 0 } },
-        { njs_number_constructor,   { NJS_SKIP_ARG, NJS_NUMBER_ARG } },
-        { njs_string_constructor,   { NJS_SKIP_ARG, NJS_STRING_ARG } },
-        { njs_function_constructor, { 0 } },
+        { njs_object_constructor,     { 0 } },
+        { njs_array_constructor,      { 0 } },
+        { njs_boolean_constructor,    { 0 } },
+        { njs_number_constructor,     { NJS_SKIP_ARG, NJS_NUMBER_ARG } },
+        { njs_string_constructor,     { NJS_SKIP_ARG, NJS_STRING_ARG } },
+        { njs_function_constructor,   { 0 } },
         { njs_regexp_constructor,
           { NJS_SKIP_ARG, NJS_STRING_ARG, NJS_STRING_ARG } },
-        { njs_date_constructor,     { 0 } },
+        { njs_date_constructor,       { 0 } },
     };
 
     static const njs_object_init_t    *object_init[] = {
index 0d2bd0881baf4a74fa03c54682152d2984f4420d..9fdda918ae893c0d61a588a95fc32eda7d0c7eb6 100644 (file)
@@ -47,6 +47,14 @@ struct njs_function_lambda_s {
 
 #define NJS_FRAME_SPARE_SIZE       512
 
+
+typedef struct {
+    njs_function_native_t          function;
+    u_char                         *return_address;
+    njs_index_t                    retval;
+} njs_continuation_t;
+
+
 #define njs_continuation(frame)                                               \
     (void *) ((u_char *) frame + NJS_NATIVE_FRAME_SIZE)
 
index 4d51c1290094fe50d749b82fa7eb2466edd0789f..7beb718b2e2f2983341da5e7a902a9b5a0f686ad 100644 (file)
@@ -292,7 +292,6 @@ njs_regexp_pattern_create(njs_vm_t *vm, u_char *start, size_t length,
     }
 
     pattern->flags = size;
-    pattern->next = NULL;
 
     p = (u_char *) pattern + sizeof(njs_regexp_pattern_t);
     pattern->source = p;
index 4e16d89f80a68d17e234e2cf2bbbb42bc90f9aab..e05ae3c1e22c4349d1b6ed86b955663890245f4d 100644 (file)
@@ -19,7 +19,6 @@ typedef enum {
 struct njs_regexp_pattern_s {
     nxt_regex_t           regex[2];
 
-    njs_regexp_pattern_t  *next;
     /*
      * A pattern source is used by RegExp.toString() method and
      * RegExp.source property.  So it is is stored in form "/pattern/flags"
index 481da3afaf4cc01d8002d902a0ce294bae92d2f8..60995ded7a7685f41cc53195a7f194d6696b775e 100644 (file)
@@ -162,7 +162,7 @@ njs_vmcode_interpreter(njs_vm_t *vm)
     njs_native_frame_t    *previous;
     njs_vmcode_generic_t  *vmcode;
 
-    start:
+start:
 
     for ( ;; ) {
 
index 9aab8025901c586a94217c605cc9c5af7473ec89..cce7be7f7b971acd9f11e7b65187f83a98855ae7 100644 (file)
@@ -124,15 +124,6 @@ typedef struct njs_native_frame_s     njs_native_frame_t;
 typedef struct njs_property_next_s    njs_property_next_t;
 
 
-typedef struct njs_continuation_s     njs_continuation_t;
-
-struct njs_continuation_s {
-    njs_function_native_t             function;
-    u_char                            *return_address;
-    njs_index_t                       retval;
-};
-
-
 union njs_value_s {
     /*
      * The njs_value_t size is 16 bytes and must be aligned to 16 bytes
index 3fcbaa9aa4c26c3a36a9f32f20583551d51bca3f..725c3f694d543f270309ef99a1bb3ce752b01819 100644 (file)
@@ -5572,11 +5572,11 @@ njs_unit_test_benchmark(nxt_str_t *script, nxt_str_t *result, const char *msg,
          + usage.ru_stime.tv_sec * 1000000 + usage.ru_stime.tv_usec;
 
     if (n == 1) {
-        us /= 1000;
-        printf("%s: %d.%03ds\n", msg, (int) (us / 1000), (int) (us % 1000));
+        printf("%s: %.3fs\n", msg, (double) us / 1000000);
 
     } else {
-        printf("%s: %d\n", msg, (int) ((uint64_t) n * 1000000 / us));
+        printf("%s: %.3fµs, %d times/s\n",
+               msg, (double) us / n, (int) ((uint64_t) n * 1000000 / us));
     }
 
     return NXT_OK;
index 06a47d53e5884002d1f69fed3fd3375834c1982a..b270b4f5c81cc9947fad6c181ed283e6d5dda693 100644 (file)
@@ -52,12 +52,12 @@ struct nxt_mem_cache_page_s {
      * Used to link pages with free chunks in pool chunk slot list
      * or to link free pages in clusters.
      */
-    nxt_queue_link_t             link;
+    nxt_queue_link_t            link;
 };
 
 
 typedef struct {
-    NXT_RBTREE_NODE              (node);
+    NXT_RBTREE_NODE             (node);
     uint8_t                     type;
     uint32_t                    size;
 
@@ -67,7 +67,7 @@ typedef struct {
 
 
 typedef struct {
-    nxt_queue_t                  pages;
+    nxt_queue_t                 pages;
 #if (NXT_64BIT)
     uint32_t                    size;
     uint32_t                    chunks;
@@ -80,9 +80,9 @@ typedef struct {
 
 struct nxt_mem_cache_pool_s {
     /* rbtree of nxt_mem_cache_block_t. */
-    nxt_rbtree_t                 blocks;
+    nxt_rbtree_t                blocks;
 
-    nxt_queue_t                  free_pages;
+    nxt_queue_t                 free_pages;
 
     uint8_t                     chunk_size_shift;
     uint8_t                     page_size_shift;
@@ -90,11 +90,11 @@ struct nxt_mem_cache_pool_s {
     uint32_t                    page_alignment;
     uint32_t                    cluster_size;
 
-    const nxt_mem_proto_t        *proto;
+    const nxt_mem_proto_t       *proto;
     void                        *mem;
     void                        *trace;
 
-    nxt_mem_cache_slot_t         slots[];
+    nxt_mem_cache_slot_t        slots[];
 };
 
 
@@ -515,7 +515,7 @@ nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool)
     n = pool->cluster_size >> pool->page_size_shift;
 
     cluster = pool->proto->zalloc(pool->mem, sizeof(nxt_mem_cache_block_t)
-                                             + n * sizeof(nxt_mem_cache_page_t));
+                                           + n * sizeof(nxt_mem_cache_page_t));
 
     if (nxt_slow_path(cluster == NULL)) {
         return NULL;
index 0b28cf4e65e2e36b347b97bf749665dfd3702e94..9fa997333789281c55dd60658c4e3c058ee347e8 100644 (file)
  * instructions are longer.
  */
 #define NXT_INT_T_SIZE  4
-typedef int            nxt_int_t;
-typedef u_int          nxt_uint_t;
+typedef int             nxt_int_t;
+typedef u_int           nxt_uint_t;
 
 #else
 #define NXT_INT_T_SIZE  NXT_PTR_SIZE
-typedef intptr_t       nxt_int_t;
-typedef uintptr_t      nxt_uint_t;
+typedef intptr_t        nxt_int_t;
+typedef uintptr_t       nxt_uint_t;
 #endif
 
 
index 27d6b69230c42fd28dfb1a35ef4f9ae9b95b8467..bf5367c51a3029391eb31fad564a10ee6a1d6c30 100644 (file)
@@ -88,7 +88,7 @@ lvlhsh_unit_test_get(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto,
 
     lhq.key_hash = key;
     lhq.key.length = sizeof(uintptr_t);
-    lhq.key.start =  (u_char *) &key;
+    lhq.key.start = (u_char *) &key;
     lhq.proto = proto;
 
     if (nxt_lvlhsh_find(lh, &lhq) == NXT_OK) {
@@ -206,8 +206,8 @@ lvlhsh_unit_test(nxt_uint_t n)
     const size_t          cluster_size = 4096;
 
     pool = nxt_mem_cache_pool_create(&mem_cache_pool_proto, NULL, NULL,
-                                    cluster_size, page_alignment,
-                                    page_size, min_chunk_size);
+                                     cluster_size, page_alignment,
+                                     page_size, min_chunk_size);
     if (pool == NULL) {
         return NXT_ERROR;
     }
index 3f1ed39fcda93c69699f0b0662fbac8ba21b819c..dc04e0d503d4b969d6fdae409d6087bc44b5d8ff 100644 (file)
@@ -82,7 +82,7 @@ utf8_overlong(u_char *overlong, size_t len)
 
 
 static nxt_int_t
-utf8_unit_test(void)
+utf8_unit_test(nxt_uint_t start)
 {
     u_char        *p, utf8[4];
     size_t        len;
@@ -142,7 +142,7 @@ utf8_unit_test(void)
 
     /* Test all overlong UTF-8. */
 
-    for (i = NXT_UTF8_START_TEST; i < 256; i++) {
+    for (i = start; i < 256; i++) {
         utf8[0] = i;
 
         if (utf8_overlong(utf8, 1) != NXT_OK) {
@@ -190,7 +190,16 @@ utf8_unit_test(void)
 
 
 int
-main(void)
+main(int argc, char **argv)
 {
-    return utf8_unit_test();
+    nxt_uint_t  start;
+
+    if (argc > 1 && argv[1][0] == 'a') {
+        start = NXT_UTF8_START_TEST;
+
+    } else {
+        start = 256;
+    }
+
+    return utf8_unit_test(start);
 }