summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Keller <skeller@gnome.org>2023-04-20 21:28:10 +0200
committerSebastian Keller <skeller@gnome.org>2023-04-20 21:28:10 +0200
commita76d23f79ef558dbed8109d5469abeb5d6a78666 (patch)
tree6dc6d5428446df8e1b64095dd3e2bbcd1e1e13b4
parentad18733acad92cbd69e63d283931ca8f4ca93d1f (diff)
downloadnautilus-a76d23f79ef558dbed8109d5469abeb5d6a78666.tar.gz
file: Re-use local time zone when generating date string
Whenever g_time_zone_new_local() is called it has to check the file system for changes, because the system's time zone might have changed since the last call. This function was called multiple times for each file when generating the date string, which was causing some unnecessary overhead. This changes the code to re-use the local time zone from the first call.
-rw-r--r--src/nautilus-file.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index ee1ff57c9..15859b6fe 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -5346,18 +5346,25 @@ nautilus_file_get_date_as_string (NautilusFile *file,
file_date_time = g_date_time_new_from_unix_local (file_time_raw);
if (date_format != NAUTILUS_DATE_FORMAT_FULL)
{
+ GTimeZone *local_tz;
GDateTime *file_date;
- now = g_date_time_new_now_local ();
- today_midnight = g_date_time_new_local (g_date_time_get_year (now),
- g_date_time_get_month (now),
- g_date_time_get_day_of_month (now),
- 0, 0, 0);
-
- file_date = g_date_time_new_local (g_date_time_get_year (file_date_time),
- g_date_time_get_month (file_date_time),
- g_date_time_get_day_of_month (file_date_time),
- 0, 0, 0);
+ /* Re-use local time zone, because every time a new local time zone is
+ * created, glib needs to check if the time zone file has changed */
+ local_tz = g_date_time_get_timezone (file_date_time);
+
+ now = g_date_time_new_now (local_tz);
+ today_midnight = g_date_time_new (local_tz,
+ g_date_time_get_year (now),
+ g_date_time_get_month (now),
+ g_date_time_get_day_of_month (now),
+ 0, 0, 0);
+
+ file_date = g_date_time_new (local_tz,
+ g_date_time_get_year (file_date_time),
+ g_date_time_get_month (file_date_time),
+ g_date_time_get_day_of_month (file_date_time),
+ 0, 0, 0);
days_ago = g_date_time_difference (today_midnight, file_date) / G_TIME_SPAN_DAY;