[Groonga-commit] groonga/groonga at 3ded623 [master] Reduce the number of grn_getenv() calls for DB

Back to archive index

Kouhei Sutou null+****@clear*****
Wed May 13 12:03:41 JST 2015


Kouhei Sutou	2015-05-13 12:03:41 +0900 (Wed, 13 May 2015)

  New Revision: 3ded62388c4a28d73b900af0fb8c511d5df24f02
  https://github.com/groonga/groonga/commit/3ded62388c4a28d73b900af0fb8c511d5df24f02

  Message:
    Reduce the number of grn_getenv() calls for DB
    
    We just call them once on init.

  Modified files:
    lib/ctx.c
    lib/db.c
    lib/grn_db.h

  Modified: lib/ctx.c (+1 -0)
===================================================================
--- lib/ctx.c    2015-05-13 11:57:16 +0900 (e5ac364)
+++ lib/ctx.c    2015-05-13 12:03:41 +0900 (585f68a)
@@ -91,6 +91,7 @@ grn_init_from_env(void)
     }
   }
 
+  grn_db_init_from_env();
   grn_plugin_init_from_env();
 }
 

  Modified: lib/db.c (+31 -19)
===================================================================
--- lib/db.c    2015-05-13 11:57:16 +0900 (f6c18b2)
+++ lib/db.c    2015-05-13 12:03:41 +0900 (3f8a521)
@@ -85,6 +85,33 @@ inline static void
 grn_obj_get_range_info(grn_ctx *ctx, grn_obj *obj,
                        grn_id *range_id, grn_obj_flags *range_flags);
 
+
+static char grn_db_key[GRN_ENV_BUFFER_SIZE];
+static uint64_t grn_index_sparsity = 10;
+
+void
+grn_db_init_from_env(void)
+{
+  grn_getenv("GRN_DB_KEY",
+             grn_db_key,
+             GRN_ENV_BUFFER_SIZE);
+
+  {
+    char grn_index_sparsity_env[GRN_ENV_BUFFER_SIZE];
+    grn_getenv("GRN_INDEX_SPARSITY",
+               grn_index_sparsity_env,
+               GRN_ENV_BUFFER_SIZE);
+    if (grn_index_sparsity_env[0]) {
+      uint64_t sparsity;
+      errno = 0;
+      sparsity = strtoull(grn_index_sparsity_env, NULL, 0);
+      if (errno == 0) {
+        grn_index_sparsity = sparsity;
+      }
+    }
+  }
+}
+
 inline static void
 gen_pathname(const char *path, char *buffer, int fno)
 {
@@ -155,15 +182,11 @@ grn_db_create(grn_ctx *ctx, const char *path, grn_db_create_optarg *optarg)
     if ((s = GRN_MALLOC(sizeof(grn_db)))) {
       grn_bool use_default_db_key = GRN_TRUE;
       grn_bool use_pat_as_db_keys = GRN_FALSE;
-      char grn_db_key_env[GRN_ENV_BUFFER_SIZE];
-      grn_getenv("GRN_DB_KEY",
-                 grn_db_key_env,
-                 GRN_ENV_BUFFER_SIZE);
-      if (grn_db_key_env[0]) {
-        if (!strcmp(grn_db_key_env, "pat")) {
+      if (grn_db_key[0]) {
+        if (!strcmp(grn_db_key, "pat")) {
           use_default_db_key = GRN_FALSE;
           use_pat_as_db_keys = GRN_TRUE;
-        } else if (!strcmp(grn_db_key_env, "dat")) {
+        } else if (!strcmp(grn_db_key, "dat")) {
           use_default_db_key = GRN_FALSE;
         }
       }
@@ -7359,18 +7382,7 @@ build_index(grn_ctx *ctx, grn_obj *obj)
           }
         }
         if (use_grn_ii_build) {
-          uint64_t sparsity = 10;
-          char grn_index_sparsity_env[GRN_ENV_BUFFER_SIZE];
-          grn_getenv("GRN_INDEX_SPARSITY",
-                     grn_index_sparsity_env,
-                     GRN_ENV_BUFFER_SIZE);
-          if (grn_index_sparsity_env[0]) {
-            uint64_t v;
-            errno = 0;
-            v = strtoull(grn_index_sparsity_env, NULL, 0);
-            if (!errno) { sparsity = v; }
-          }
-          grn_ii_build(ctx, ii, sparsity);
+          grn_ii_build(ctx, ii, grn_index_sparsity);
         } else {
           grn_table_cursor  *tc;
           if ((tc = grn_table_cursor_open(ctx, target, NULL, 0, NULL, 0,

  Modified: lib/grn_db.h (+2 -0)
===================================================================
--- lib/grn_db.h    2015-05-13 11:57:16 +0900 (cbc2ccc)
+++ lib/grn_db.h    2015-05-13 12:03:41 +0900 (6c84ad9)
@@ -56,6 +56,8 @@ typedef struct {
   grn_id range;
 } grn_obj_spec;
 
+void grn_db_init_from_env(void);
+
 GRN_API grn_rc grn_db_close(grn_ctx *ctx, grn_obj *db);
 
 grn_obj *grn_db_keys(grn_obj *s);
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index