[tracker/wip/carlosg/anonymous-nodes: 1/24] libtracker-data: Minor refactor
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/anonymous-nodes: 1/24] libtracker-data: Minor refactor
- Date: Fri, 8 Oct 2021 09:40:53 +0000 (UTC)
commit a98d94e147eac98a16b67003d52129afa36d5d1f
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Sep 19 12:44:48 2021 +0200
libtracker-data: Minor refactor
There is a small pattern here, move it to a separate function.
src/libtracker-data/tracker-sparql.c | 62 ++++++++++++++----------------------
1 file changed, 24 insertions(+), 38 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index b562bd97d..334879486 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -6836,29 +6836,39 @@ translate_TriplesNode (TrackerSparql *sparql,
return TRUE;
}
-static gboolean
-translate_BlankNodePropertyList (TrackerSparql *sparql,
- GError **error)
+static void
+tracker_sparql_generate_bnode (TrackerSparql *sparql,
+ TrackerToken *token)
{
- TrackerToken old_subject = sparql->current_state->subject;
- TrackerVariable *var;
-
- /* BlankNodePropertyList ::= '[' PropertyListNotEmpty ']'
- */
- _expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_BRACKET);
+ if (sparql->current_state->type == TRACKER_SPARQL_TYPE_SELECT ||
+ sparql->current_state->type == TRACKER_SPARQL_TYPE_CONSTRUCT) {
+ TrackerVariable *var;
- if (sparql->current_state->type == TRACKER_SPARQL_TYPE_SELECT) {
var = tracker_select_context_add_generated_variable (TRACKER_SELECT_CONTEXT
(sparql->context));
- tracker_token_variable_init (&sparql->current_state->subject, var);
+ tracker_token_variable_init (token, var);
} else {
TrackerDBInterface *iface;
gchar *bnode_id;
iface = tracker_data_manager_get_writable_db_interface (sparql->data_manager);
bnode_id = tracker_data_query_unused_uuid (sparql->data_manager, iface);
- tracker_token_literal_init (&sparql->current_state->subject, bnode_id, -1);
+ tracker_token_literal_init (token, bnode_id, -1);
g_free (bnode_id);
}
+}
+
+static gboolean
+translate_BlankNodePropertyList (TrackerSparql *sparql,
+ GError **error)
+{
+ TrackerToken old_subject = sparql->current_state->subject;
+
+ /* BlankNodePropertyList ::= '[' PropertyListNotEmpty ']'
+ */
+ _expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_BRACKET);
+
+ tracker_sparql_generate_bnode (sparql,
+ &sparql->current_state->subject);
_call_rule (sparql, NAMED_RULE_PropertyListNotEmpty, error);
@@ -6951,19 +6961,7 @@ translate_Collection (TrackerSparql *sparql,
g_array_set_size (elems, elems->len + 1);
cur = &g_array_index (elems, TrackerToken, 0);
- if (sparql->current_state->type == TRACKER_SPARQL_TYPE_SELECT) {
- TrackerVariable *var;
- var = tracker_select_context_add_generated_variable (TRACKER_SELECT_CONTEXT
(sparql->context));
- tracker_token_variable_init (cur, var);
- } else {
- TrackerDBInterface *iface;
- gchar *bnode_id;
-
- iface = tracker_data_manager_get_writable_db_interface (sparql->data_manager);
- bnode_id = tracker_data_query_unused_uuid (sparql->data_manager, iface);
- tracker_token_literal_init (cur, bnode_id, -1);
- g_free (bnode_id);
- }
+ tracker_sparql_generate_bnode (sparql, cur);
}
sparql->current_state->subject = *cur;
@@ -6997,19 +6995,7 @@ translate_Collection (TrackerSparql *sparql,
g_array_set_size (elems, elems->len + 1);
cur = &g_array_index (elems, TrackerToken, elems->len - 1);
- if (sparql->current_state->type == TRACKER_SPARQL_TYPE_SELECT) {
- TrackerVariable *var;
- var = tracker_select_context_add_generated_variable (TRACKER_SELECT_CONTEXT
(sparql->context));
- tracker_token_variable_init (cur, var);
- } else {
- TrackerDBInterface *iface;
- gchar *bnode_id;
-
- iface = tracker_data_manager_get_writable_db_interface (sparql->data_manager);
- bnode_id = tracker_data_query_unused_uuid (sparql->data_manager, iface);
- tracker_token_literal_init (cur, bnode_id, -1);
- g_free (bnode_id);
- }
+ tracker_sparql_generate_bnode (sparql, cur);
sparql->current_state->object = *cur;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]