summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2022-12-31 14:19:46 +0100
committerCarlos Garnacho <carlosg@gnome.org>2023-01-10 15:36:23 +0100
commitc2006110204f9798c96b5238b1325970aa7239b8 (patch)
tree8d662e01fcf3751a6bbc0ecd4a181ba23f9ac8ce
parent9dc2f1067c69f38ad7e28329234df725e8fc5db8 (diff)
downloadtracker-c2006110204f9798c96b5238b1325970aa7239b8.tar.gz
core: Use direct strftime() on SparqlPrintValue
The allocation, string composition and freeing of GDateTime may turn into a hottish path if the resultset has a high amount of strings. Resort to strftime() on a fixed buffer in order to reduce malloc/free overhead.
-rw-r--r--src/libtracker-sparql/core/tracker-db-interface-sqlite.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
index c8e221c0c..eb99e226f 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
@@ -1890,27 +1890,27 @@ function_sparql_print_value (sqlite3_context *context,
case TRACKER_PROPERTY_TYPE_DATE:
case TRACKER_PROPERTY_TYPE_DATETIME:
if (sqlite3_value_numeric_type (argv[0]) == SQLITE_INTEGER) {
- GDateTime *datetime;
+ struct tm tm;
gint64 timestamp;
+ gchar buf[100];
+ int retval;
timestamp = sqlite3_value_int64 (argv[0]);
- datetime = g_date_time_new_from_unix_utc (timestamp);
- if (datetime) {
- gchar *str;
+ if (gmtime_r ((time_t *) &timestamp, &tm) == NULL)
+ result_context_function_error (context, fn, "Invalid unix timestamp");
- if (prop_type == TRACKER_PROPERTY_TYPE_DATETIME)
- str = tracker_date_format_iso8601 (datetime);
- else if (prop_type == TRACKER_PROPERTY_TYPE_DATE)
- str = g_date_time_format (datetime, "%Y-%m-%d");
- else
- g_assert_not_reached ();
+ if (prop_type == TRACKER_PROPERTY_TYPE_DATETIME)
+ retval = strftime ((gchar *) &buf, sizeof (buf), "%2C%y-%m-%dT%TZ", &tm);
+ else if (prop_type == TRACKER_PROPERTY_TYPE_DATE)
+ retval = strftime ((gchar *) &buf, sizeof (buf), "%2C%y-%m-%d", &tm);
+ else
+ g_assert_not_reached ();
- sqlite3_result_text (context, str, -1, g_free);
- g_date_time_unref (datetime);
- } else {
- sqlite3_result_null (context);
- }
+ if (retval != 0)
+ sqlite3_result_text (context, g_strdup (buf), -1, g_free);
+ else
+ result_context_function_error (context, fn, "Invalid unix timestamp");
} else if (sqlite3_value_type (argv[0]) == SQLITE_TEXT) {
if (prop_type == TRACKER_PROPERTY_TYPE_DATETIME) {
sqlite3_result_value (context, argv[0]);