[Groonga-commit] groonga/groonga at 526ca68 [master] Extract common code

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Apr 7 21:59:08 JST 2015


Kouhei Sutou	2015-04-07 21:59:08 +0900 (Tue, 07 Apr 2015)

  New Revision: 526ca6810f5cec1baf5f254c285521e230c4580f
  https://github.com/groonga/groonga/commit/526ca6810f5cec1baf5f254c285521e230c4580f

  Message:
    Extract common code

  Modified files:
    lib/expr.c

  Modified: lib/expr.c (+17 -14)
===================================================================
--- lib/expr.c    2015-04-07 16:27:17 +0900 (f4df713)
+++ lib/expr.c    2015-04-07 21:59:08 +0900 (f7d13aa)
@@ -720,6 +720,21 @@ grn_expr_get_var_by_offset(grn_ctx *ctx, grn_obj *expr, unsigned int offset)
   DFI_PUT(e, type, domain, code);                               \
 } while (0)
 
+static void
+grn_expr_append_obj_resolve_const(grn_ctx *ctx,
+                                  grn_obj *obj,
+                                  grn_id to_domain)
+{
+  grn_obj dest;
+
+  GRN_OBJ_INIT(&dest, GRN_BULK, 0, to_domain);
+  if (!grn_obj_cast(ctx, obj, &dest, GRN_FALSE)) {
+    grn_obj_reinit(ctx, obj, to_domain, 0);
+    grn_bulk_write(ctx, obj, GRN_BULK_HEAD(&dest), GRN_BULK_VSIZE(&dest));
+  }
+  GRN_OBJ_FIN(ctx, &dest);
+}
+
 grn_obj *
 grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op, int nargs)
 {
@@ -852,26 +867,14 @@ grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op,
           if (CONSTP(y)) {
             /* todo */
           } else {
-            grn_obj dest;
             if (xd != yd) {
-              GRN_OBJ_INIT(&dest, GRN_BULK, 0, yd);
-              if (!grn_obj_cast(ctx, x, &dest, GRN_FALSE)) {
-                grn_obj_reinit(ctx, x, yd, 0);
-                grn_bulk_write(ctx, x, GRN_BULK_HEAD(&dest), GRN_BULK_VSIZE(&dest));
-              }
-              GRN_OBJ_FIN(ctx, &dest);
+              grn_expr_append_obj_resolve_const(ctx, x, yd);
             }
           }
         } else {
           if (CONSTP(y)) {
-            grn_obj dest;
             if (xd != yd) {
-              GRN_OBJ_INIT(&dest, GRN_BULK, 0, xd);
-              if (!grn_obj_cast(ctx, y, &dest, GRN_FALSE)) {
-                grn_obj_reinit(ctx, y, xd, 0);
-                grn_bulk_write(ctx, y, GRN_BULK_HEAD(&dest), GRN_BULK_VSIZE(&dest));
-              }
-              GRN_OBJ_FIN(ctx, &dest);
+              grn_expr_append_obj_resolve_const(ctx, y, xd);
             }
           }
         }
-------------- next part --------------
HTML����������������������������...
다운로드 



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