Navigation Menu

Skip to content

Commit

Permalink
Extract common code
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 7, 2015
1 parent 5f181fa commit 526ca68
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions lib/expr.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 526ca68

Please sign in to comment.