[Groonga-commit] groonga/groonga [master] Reduced grn_proc_get_info call from proc.c moreover.

アーカイブの一覧に戻る

null+****@clear***** null+****@clear*****
2010年 6月 15日 (火) 08:58:06 JST


Daijiro MORI	2010-06-14 23:58:06 +0000 (Mon, 14 Jun 2010)

  New Revision: 7831b522bbd35ad841bf3943c47025ae49d555df

  Log:
    Reduced grn_proc_get_info call from proc.c moreover.

  Modified files:
    lib/db.h
    lib/expr.c
    lib/proc.c

  Modified: lib/db.h (+1 -1)
===================================================================
--- lib/db.h    2010-06-14 18:34:27 +0000 (e1a5c7f)
+++ lib/db.h    2010-06-14 23:58:06 +0000 (115b7d5)
@@ -181,7 +181,7 @@ struct _grn_proc {
 
 #define GRN_PROC_GET_VAR(name) (grn_proc_get_var(ctx, user_data, name, strlen(name)))
 #define GRN_PROC_GET_VAR_BY_OFFSET(offset) (grn_proc_get_var_by_offset(ctx, user_data, offset))
-#define GRN_PROC_ALLOC(offset) (grn_proc_alloc(ctx, user_data, domain, flags))
+#define GRN_PROC_ALLOC(domain, flags) (grn_proc_alloc(ctx, user_data, domain, flags))
 
 grn_obj *grn_proc_get_var(grn_ctx *ctx, grn_user_data *user_data,
                           const char *name, unsigned name_size);

  Modified: lib/expr.c (+7 -5)
===================================================================
--- lib/expr.c    2010-06-14 18:34:27 +0000 (8b8c7d2)
+++ lib/expr.c    2010-06-14 23:58:06 +0000 (8188894)
@@ -98,12 +98,14 @@ grn_proc_get_info(grn_ctx *ctx, grn_user_data *user_data,
   grn_proc_ctx *pctx = (grn_proc_ctx *)user_data;
   if (caller) { *caller = pctx->caller; }
   if (pctx->proc) {
-    *vars = pctx->proc->vars;
-    *nvars = pctx->proc->nvars;
-    // *vars = grn_expr_get_vars(ctx, (grn_obj *)pctx->proc, nvars);
+    if (vars) {
+      *vars = pctx->proc->vars;
+   // *vars = grn_expr_get_vars(ctx, (grn_obj *)pctx->proc, nvars);
+    }
+    if (nvars) { *nvars = pctx->proc->nvars; }
   } else {
-    *vars = NULL;
-    *nvars = 0;
+    if (vars) { *vars = NULL; }
+    if (nvars) { *nvars = 0; }
   }
   return (grn_obj *)pctx->proc;
 }

  Modified: lib/proc.c (+18 -51)
===================================================================
--- lib/proc.c    2010-06-14 18:34:27 +0000 (8a28640)
+++ lib/proc.c    2010-06-14 23:58:06 +0000 (9a1f63e)
@@ -92,35 +92,24 @@ proc_define_selector(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *use
 {
   uint32_t nvars;
   grn_expr_var *vars;
-
   grn_proc_get_info(ctx, user_data, &vars, &nvars, NULL);
-
-  if (nvars == 17) {
-    grn_proc_create(ctx,
-                    GRN_TEXT_VALUE(VAR(0)), GRN_TEXT_LEN(VAR(0)),
-                    GRN_PROC_COMMAND, proc_select, NULL, NULL, nvars - 1, vars + 1);
-  } else {
-    ERR(GRN_INVALID_ARGUMENT, "invalid argument number. %d for %d", nvars, 16);
-  }
+  grn_proc_create(ctx,
+                  GRN_TEXT_VALUE(VAR(0)), GRN_TEXT_LEN(VAR(0)),
+                  GRN_PROC_COMMAND, proc_select, NULL, NULL, nvars - 1, vars + 1);
   return NULL;
 }
 
 static grn_obj *
 proc_load(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
-  uint32_t nvars;
   grn_obj *outbuf = ctx->impl->outbuf;
-  grn_expr_var *vars;
-
-  grn_obj *proc = grn_proc_get_info(ctx, user_data, &vars, &nvars, NULL);
-
   grn_load(ctx, grn_get_ctype(VAR(4)),
            GRN_TEXT_VALUE(VAR(1)), GRN_TEXT_LEN(VAR(1)),
            GRN_TEXT_VALUE(VAR(2)), GRN_TEXT_LEN(VAR(2)),
            GRN_TEXT_VALUE(VAR(0)), GRN_TEXT_LEN(VAR(0)),
            GRN_TEXT_VALUE(VAR(3)), GRN_TEXT_LEN(VAR(3)));
   if (ctx->impl->loader.stat != GRN_LOADER_END) {
-    grn_ctx_set_next_expr(ctx, proc);
+    grn_ctx_set_next_expr(ctx, grn_proc_get_info(ctx, user_data, NULL, NULL, NULL));
   } else {
     grn_text_itoa(ctx, outbuf, ctx->impl->loader.nrecords);
     if (ctx->impl->loader.table) {
@@ -1702,17 +1691,14 @@ static grn_obj *
 func_rand(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
   int val;
-  grn_obj *obj, *caller;
-  uint32_t nvars;
-  grn_expr_var *vars;
-  grn_proc_get_info(ctx, user_data, &vars, &nvars, &caller);
+  grn_obj *obj;
   if (nargs > 0) {
     int max = GRN_INT32_VALUE(args[0]);
     val = (int) (1.0 * max * rand() / (RAND_MAX + 1.0));
   } else {
     val = rand();
   }
-  if ((obj = grn_expr_alloc(ctx, caller, GRN_DB_INT32, 0))) {
+  if ((obj = GRN_PROC_ALLOC(GRN_DB_INT32, 0))) {
     GRN_INT32_SET(ctx, obj, val);
   }
   return obj;
@@ -1721,11 +1707,8 @@ func_rand(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 static grn_obj *
 func_now(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
-  uint32_t nvars;
-  grn_expr_var *vars;
-  grn_obj *obj, *caller;
-  grn_proc_get_info(ctx, user_data, &vars, &nvars, &caller);
-  if ((obj = grn_expr_alloc(ctx, caller, GRN_DB_TIME, 0))) {
+  grn_obj *obj;
+  if ((obj = GRN_PROC_ALLOC(GRN_DB_TIME, 0))) {
     GRN_TIME_NOW(ctx, obj);
   }
   return obj;
@@ -1744,11 +1727,8 @@ func_now(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 static grn_obj *
 func_geo_in_circle(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
-  grn_obj *obj, *caller;
-  uint32_t nvars;
-  grn_expr_var *vars;
+  grn_obj *obj;
   unsigned char r = GRN_FALSE;
-  grn_proc_get_info(ctx, user_data, &vars, &nvars, &caller);
   if (nargs == 3) {
     grn_obj *pos = args[0], *pos1 = args[1], *pos2 = args[2], pos1_, pos2_;
     grn_id domain = pos->header.domain;
@@ -1804,7 +1784,7 @@ func_geo_in_circle(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_
     }
   }
 exit :
-  if ((obj = grn_expr_alloc(ctx, caller, GRN_DB_UINT32, 0))) {
+  if ((obj = GRN_PROC_ALLOC(GRN_DB_UINT32, 0))) {
     GRN_UINT32_SET(ctx, obj, r);
   }
   return obj;
@@ -1813,11 +1793,8 @@ exit :
 static grn_obj *
 func_geo_in_rectangle(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
-  grn_obj *obj, *caller;
-  uint32_t nvars;
-  grn_expr_var *vars;
+  grn_obj *obj;
   unsigned char r = GRN_FALSE;
-  grn_proc_get_info(ctx, user_data, &vars, &nvars, &caller);
   if (nargs == 3) {
     grn_obj *pos = args[0], *pos1 = args[1], *pos2 = args[2], pos1_, pos2_;
     grn_geo_point *p, *p1, *p2;
@@ -1841,7 +1818,7 @@ func_geo_in_rectangle(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *us
     }
   }
 exit :
-  if ((obj = grn_expr_alloc(ctx, caller, GRN_DB_UINT32, 0))) {
+  if ((obj = GRN_PROC_ALLOC(GRN_DB_UINT32, 0))) {
     GRN_UINT32_SET(ctx, obj, r);
   }
   return obj;
@@ -1850,11 +1827,8 @@ exit :
 static grn_obj *
 func_geo_distance(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
-  grn_obj *obj, *caller;
-  uint32_t nvars;
-  grn_expr_var *vars;
+  grn_obj *obj;
   double d = 0;
-  grn_proc_get_info(ctx, user_data, &vars, &nvars, &caller);
   if (nargs == 2) {
     grn_obj *pos = args[0], *pos1 = args[1], pos1_;
     grn_id domain = pos->header.domain;
@@ -1875,7 +1849,7 @@ func_geo_distance(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_d
     }
   }
 exit :
-  if ((obj = grn_expr_alloc(ctx, caller, GRN_DB_FLOAT, 0))) {
+  if ((obj = GRN_PROC_ALLOC(GRN_DB_FLOAT, 0))) {
     GRN_FLOAT_SET(ctx, obj, d);
   }
   return obj;
@@ -1884,11 +1858,8 @@ exit :
 static grn_obj *
 func_geo_distance2(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
-  grn_obj *obj, *caller;
-  uint32_t nvars;
-  grn_expr_var *vars;
+  grn_obj *obj;
   double d = 0;
-  grn_proc_get_info(ctx, user_data, &vars, &nvars, &caller);
   if (nargs == 2) {
     grn_obj *pos = args[0], *pos1 = args[1], pos1_;
     grn_id domain = pos->header.domain;
@@ -1909,7 +1880,7 @@ func_geo_distance2(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_
     }
   }
 exit :
-  if ((obj = grn_expr_alloc(ctx, caller, GRN_DB_FLOAT, 0))) {
+  if ((obj = GRN_PROC_ALLOC(GRN_DB_FLOAT, 0))) {
     GRN_FLOAT_SET(ctx, obj, d);
   }
   return obj;
@@ -1918,12 +1889,8 @@ exit :
 static grn_obj *
 func_geo_distance3(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
-  grn_obj *obj, *caller;
-  uint32_t nvars;
-  grn_expr_var *vars;
+  grn_obj *obj;
   double d = 0;
-  grn_proc_get_info(ctx, user_data, &vars, &nvars, &caller);
-
   if (nargs == 2) {
     grn_obj *pos = args[0], *pos1 = args[1], pos1_;
     grn_id domain = pos->header.domain;
@@ -1978,7 +1945,7 @@ func_geo_distance3(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_
     }
   }
 exit :
-  if ((obj = grn_expr_alloc(ctx, caller, GRN_DB_FLOAT, 0))) {
+  if ((obj = GRN_PROC_ALLOC(GRN_DB_FLOAT, 0))) {
     GRN_FLOAT_SET(ctx, obj, d);
   }
   return obj;




Groonga-commit メーリングリストの案内
アーカイブの一覧に戻る