[tracker/wip/carlosg/unbound-vars: 1/3] libtracker-data: Allow looking up variables in context by name
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/unbound-vars: 1/3] libtracker-data: Allow looking up variables in context by name
- Date: Sun, 30 Aug 2020 21:26:42 +0000 (UTC)
commit 97474303800141fbd4db71d91684474dc32cbba0
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Aug 29 14:25:10 2020 +0200
libtracker-data: Allow looking up variables in context by name
Getting a TrackerVariable first is a bit of an egg/chicken problem,
since getting a TrackerVariable ensures it's referenced in the context
in all code paths.
Soften this a bit, and allow to look up variables by name, without
necessarily creating a TrackerVariable for it.
src/libtracker-data/tracker-sparql-types.c | 22 ++++++++++++++--------
src/libtracker-data/tracker-sparql-types.h | 2 ++
src/libtracker-data/tracker-sparql.c | 10 +++++-----
3 files changed, 21 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-types.c b/src/libtracker-data/tracker-sparql-types.c
index a029a275e..a638620b2 100644
--- a/src/libtracker-data/tracker-sparql-types.c
+++ b/src/libtracker-data/tracker-sparql-types.c
@@ -653,8 +653,7 @@ tracker_context_class_init (TrackerContextClass *klass)
static void
tracker_context_init (TrackerContext *context)
{
- context->variable_set = g_hash_table_new (tracker_variable_hash,
- tracker_variable_equal);
+ context->variable_set = g_hash_table_new (g_str_hash, g_str_equal);
}
TrackerContext *
@@ -684,27 +683,34 @@ void
tracker_context_add_variable_ref (TrackerContext *context,
TrackerVariable *variable)
{
- g_hash_table_add (context->variable_set, variable);
+ g_hash_table_insert (context->variable_set, variable->name, variable);
}
gboolean
tracker_context_lookup_variable_ref (TrackerContext *context,
TrackerVariable *variable)
{
- return g_hash_table_lookup (context->variable_set, variable) != NULL;
+ return g_hash_table_lookup (context->variable_set, variable->name) != NULL;
+}
+
+gboolean
+tracker_context_lookup_variable_by_name (TrackerContext *context,
+ const gchar *name)
+{
+ return g_hash_table_lookup (context->variable_set, name) != NULL;
}
void
tracker_context_propagate_variables (TrackerContext *context)
{
GHashTableIter iter;
- gpointer key;
+ gpointer key, value;
g_assert (context->parent != NULL);
g_hash_table_iter_init (&iter, context->variable_set);
- while (g_hash_table_iter_next (&iter, &key, NULL))
- g_hash_table_add (context->parent->variable_set, key);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ g_hash_table_insert (context->parent->variable_set, key, value);
}
/* Select context */
@@ -985,7 +991,7 @@ tracker_triple_context_get_variable_binding_list (TrackerTripleContext *context,
*/
if (TRACKER_IS_SELECT_CONTEXT (current_context) &&
tracker_context_get_parent (current_context) &&
- g_hash_table_lookup (parent_context->variable_set, variable)) {
+ g_hash_table_lookup (parent_context->variable_set, variable->name)) {
TrackerVariableBinding *sample;
TrackerBinding *binding;
diff --git a/src/libtracker-data/tracker-sparql-types.h b/src/libtracker-data/tracker-sparql-types.h
index fc79798b7..8dc551234 100644
--- a/src/libtracker-data/tracker-sparql-types.h
+++ b/src/libtracker-data/tracker-sparql-types.h
@@ -346,6 +346,8 @@ void tracker_context_add_variable_ref (TrackerContext *context,
TrackerVariable *variable);
gboolean tracker_context_lookup_variable_ref (TrackerContext *context,
TrackerVariable *variable);
+gboolean tracker_context_lookup_variable_by_name (TrackerContext *context,
+ const gchar *name);
/* Select context */
GType tracker_select_context_get_type (void) G_GNUC_CONST;
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 5a2795af9..91382f5db 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -5550,13 +5550,13 @@ intersect_var_set (GHashTable *ht1,
{
GHashTableIter iter;
GList *intersection = NULL;
- gpointer key;
+ gpointer key, value;
g_hash_table_iter_init (&iter, ht1);
- while (g_hash_table_iter_next (&iter, &key, NULL)) {
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
if (g_hash_table_contains (ht2, key))
- intersection = g_list_prepend (intersection, key);
+ intersection = g_list_prepend (intersection, value);
}
return intersection;
@@ -5587,7 +5587,7 @@ translate_MinusGraphPattern (TrackerSparql *sparql,
intersection = intersect_var_set (cur_context->variable_set, context->variable_set);
- vars = g_hash_table_get_keys (cur_context->variable_set);
+ vars = g_hash_table_get_values (cur_context->variable_set);
cur = tracker_sparql_swap_builder (sparql, pre);
append_subquery_select_vars (sparql, cur_context, vars);
tracker_sparql_swap_builder (sparql, cur);
@@ -5654,7 +5654,7 @@ translate_GroupOrUnionGraphPattern (TrackerSparql *sparql,
}
} while (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_UNION));
- vars = g_hash_table_get_keys (context->variable_set);
+ vars = g_hash_table_get_values (context->variable_set);
if (placeholders->len > 1) {
/* We are performing an union of multiple GroupGraphPattern,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]