From a76d23f79ef558dbed8109d5469abeb5d6a78666 Mon Sep 17 00:00:00 2001 From: Sebastian Keller Date: Thu, 20 Apr 2023 21:28:10 +0200 Subject: 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. --- src/nautilus-file.c | 27 +++++++++++++++++---------- 1 file 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; -- cgit v1.2.1