mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-13 04:46:15 +01:00
gtimezone: Cache timezones based on the identifier they were created by
Rather than invalidating the cache by comparing `TZ` to the cached timezone identifier, key entirely off the value of `TZ` (and a cached copy of it). This fixes the timezone cache being constantly invalidated if `TZ` is `NULL` (which will always differ from the identifier of the default local timezone which is constructed from `g_time_zone_new (NULL)`. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2204
This commit is contained in:
parent
af0b0e98da
commit
851241f19a
@ -196,6 +196,7 @@ struct _GTimeZone
|
|||||||
G_LOCK_DEFINE_STATIC (time_zones);
|
G_LOCK_DEFINE_STATIC (time_zones);
|
||||||
static GHashTable/*<string?, GTimeZone>*/ *time_zones;
|
static GHashTable/*<string?, GTimeZone>*/ *time_zones;
|
||||||
G_LOCK_DEFINE_STATIC (tz_local);
|
G_LOCK_DEFINE_STATIC (tz_local);
|
||||||
|
static gchar *tzenv_cached = NULL;
|
||||||
static GTimeZone *tz_local = NULL;
|
static GTimeZone *tz_local = NULL;
|
||||||
|
|
||||||
#define MIN_TZYEAR 1916 /* Daylight Savings started in WWI */
|
#define MIN_TZYEAR 1916 /* Daylight Savings started in WWI */
|
||||||
@ -1842,11 +1843,17 @@ g_time_zone_new_local (void)
|
|||||||
G_LOCK (tz_local);
|
G_LOCK (tz_local);
|
||||||
|
|
||||||
/* Is time zone changed and must be flushed? */
|
/* Is time zone changed and must be flushed? */
|
||||||
if (tz_local && g_strcmp0 (g_time_zone_get_identifier (tz_local), tzenv))
|
if (tz_local && g_strcmp0 (tzenv, tzenv_cached) != 0)
|
||||||
g_clear_pointer (&tz_local, g_time_zone_unref);
|
{
|
||||||
|
g_clear_pointer (&tz_local, g_time_zone_unref);
|
||||||
|
g_clear_pointer (&tzenv_cached, g_free);
|
||||||
|
}
|
||||||
|
|
||||||
if (tz_local == NULL)
|
if (tz_local == NULL)
|
||||||
tz_local = g_time_zone_new (tzenv);
|
{
|
||||||
|
tz_local = g_time_zone_new (tzenv);
|
||||||
|
tzenv_cached = g_strdup (tzenv);
|
||||||
|
}
|
||||||
|
|
||||||
tz = g_time_zone_ref (tz_local);
|
tz = g_time_zone_ref (tz_local);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user