[Groonga-commit] groonga/groonga at 525ce27 [master] Split a long function

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Nov 11 17:34:15 JST 2014


Kouhei Sutou	2014-11-11 17:34:15 +0900 (Tue, 11 Nov 2014)

  New Revision: 525ce275de42ff724f4ab4f735098c16305e4f02
  https://github.com/groonga/groonga/commit/525ce275de42ff724f4ab4f735098c16305e4f02

  Message:
    Split a long function

  Modified files:
    lib/proc.c

  Modified: lib/proc.c (+41 -20)
===================================================================
--- lib/proc.c    2014-11-11 14:09:32 +0900 (cfd6c21)
+++ lib/proc.c    2014-11-11 17:34:15 +0900 (6a9315f)
@@ -5029,24 +5029,17 @@ exit :
 }
 
 static grn_bool
-selector_between_sequential_search(grn_ctx *ctx,
-                                   grn_obj *table,
-                                   grn_obj *index, grn_obj *index_table,
-                                   between_data *data,
-                                   grn_obj *res, grn_operator op)
+selector_between_sequential_search_should_use(grn_ctx *ctx,
+                                              grn_obj *table,
+                                              grn_obj *index,
+                                              grn_obj *index_table,
+                                              between_data *data,
+                                              grn_obj *res,
+                                              grn_operator op,
+                                              double too_many_index_match_ratio)
 {
-  double too_many_index_match_ratio = 0.01;
-  int n_existing_records;
   int n_index_keys;
 
-  {
-    const char *too_many_index_match_ratio_env =
-      getenv("GRN_BETWEEN_TOO_MANY_INDEX_MATCH_RATIO");
-    if (too_many_index_match_ratio_env) {
-      too_many_index_match_ratio = atof(too_many_index_match_ratio_env);
-    }
-  }
-
   if (too_many_index_match_ratio < 0.0) {
     return GRN_FALSE;
   }
@@ -5059,11 +5052,6 @@ selector_between_sequential_search(grn_ctx *ctx,
     return GRN_FALSE;
   }
 
-  n_existing_records = grn_table_size(ctx, res);
-  if (n_existing_records == 0) {
-    return GRN_TRUE;
-  }
-
   n_index_keys = grn_table_size(ctx, index_table);
   if (n_index_keys == 0) {
     return GRN_FALSE;
@@ -5099,6 +5087,7 @@ selector_between_sequential_search(grn_ctx *ctx,
       return GRN_FALSE;
     }
     if (grn_table_cursor_next(ctx, cursor) == GRN_ID_NIL) {
+      grn_table_cursor_close(ctx, cursor);
       return GRN_FALSE;
     }
     {
@@ -5116,6 +5105,7 @@ selector_between_sequential_search(grn_ctx *ctx,
       return GRN_FALSE;
     }
     if (grn_table_cursor_next(ctx, cursor) == GRN_ID_NIL) {
+      grn_table_cursor_close(ctx, cursor);
       return GRN_FALSE;
     }
     {
@@ -5132,9 +5122,13 @@ selector_between_sequential_search(grn_ctx *ctx,
      * TODO: Improve me.
      */
     {
+      int n_existing_records;
       int n_indexed_records;
       long long int all_difference;
       long long int argument_difference;
+
+      n_existing_records = grn_table_size(ctx, res);
+
       all_difference = all_max - all_min;
       if (all_difference <= 0) {
         return GRN_FALSE;
@@ -5146,6 +5140,7 @@ selector_between_sequential_search(grn_ctx *ctx,
       }
       n_indexed_records =
         n_index_keys * ((double)argument_difference / (double)all_difference);
+
       /*
        * Same as:
        * ((n_existing_record / n_indexed_records) > too_many_index_match_ratio)
@@ -5156,6 +5151,32 @@ selector_between_sequential_search(grn_ctx *ctx,
     }
   }
 
+  return GRN_TRUE;
+}
+
+static grn_bool
+selector_between_sequential_search(grn_ctx *ctx,
+                                   grn_obj *table,
+                                   grn_obj *index, grn_obj *index_table,
+                                   between_data *data,
+                                   grn_obj *res, grn_operator op)
+{
+  double too_many_index_match_ratio = 0.01;
+
+  {
+    const char *too_many_index_match_ratio_env =
+      getenv("GRN_BETWEEN_TOO_MANY_INDEX_MATCH_RATIO");
+    if (too_many_index_match_ratio_env) {
+      too_many_index_match_ratio = atof(too_many_index_match_ratio_env);
+    }
+  }
+
+  if (!selector_between_sequential_search_should_use(
+        ctx, table, index, index_table, data, res, op,
+        too_many_index_match_ratio)) {
+    return GRN_FALSE;
+  }
+
   {
     int offset = 0;
     int limit = -1;
-------------- next part --------------
HTML����������������������������...
下載 



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