summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dde59b1)
raw | patch | inline | side by side (parent: dde59b1)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 2 Aug 2014 10:57:16 +0000 (12:57 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 2 Aug 2014 10:57:16 +0000 (12:57 +0200) |
That is, when creating a new expression objects, evaluate it right away if its
left and right operands are constant values.
left and right operands are constant values.
src/core/store_expr.c | patch | blob | history |
diff --git a/src/core/store_expr.c b/src/core/store_expr.c
index 7d674bc2f6b8e77bd87432b81532b34313da17ad..9aa1ce99718fef3f42c6de7a165c8d3aef33b438 100644 (file)
--- a/src/core/store_expr.c
+++ b/src/core/store_expr.c
}
if (value)
- if (sdb_data_copy(&expr->data, value))
- return -1;
+ expr->data = *value;
sdb_object_ref(SDB_OBJ(left));
sdb_object_ref(SDB_OBJ(right));
sdb_store_expr_t *
sdb_store_expr_create(int op, sdb_store_expr_t *left, sdb_store_expr_t *right)
{
- if ((op < 0) || (SDB_DATA_CONCAT < op))
+ sdb_data_t value = SDB_DATA_INIT;
+
+ if ((op < 0) || (SDB_DATA_CONCAT < op) || (! left) || (! right))
return NULL;
- return SDB_STORE_EXPR(sdb_object_create("store-expr", expr_type,
- op, left, right, NULL));
+
+ if (left->type || right->type)
+ return SDB_STORE_EXPR(sdb_object_create("store-expr", expr_type,
+ op, left, right, NULL));
+ /* else: both expressions are constant values; evaluate now */
+
+ if (sdb_data_expr_eval(op, &left->data, &right->data, &value))
+ return NULL;
+ return SDB_STORE_EXPR(sdb_object_create("store-constvalue", expr_type,
+ 0, NULL, NULL, &value));
} /* sdb_store_expr_create */
sdb_store_expr_t *
sdb_store_expr_t *
sdb_store_expr_constvalue(const sdb_data_t *value)
{
+ sdb_data_t data = SDB_DATA_INIT;
+ if (sdb_data_copy(&data, value))
+ return NULL;
return SDB_STORE_EXPR(sdb_object_create("store-constvalue", expr_type,
- 0, NULL, NULL, value));
+ 0, NULL, NULL, &data));
} /* sdb_store_expr_constvalue */
int