From 29a074b87e60be0d3f5508fa71ceb61937777c6d Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Fri, 18 Mar 2011 23:09:17 -0400 Subject: [PATCH] GTimeZone: don't add /etc/localtime to the cache It may change. --- glib/gtimezone.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/glib/gtimezone.c b/glib/gtimezone.c index 5c39958..c8cd948 100644 --- a/glib/gtimezone.c +++ b/glib/gtimezone.c @@ -132,25 +132,6 @@ struct _GTimeZone G_LOCK_DEFINE_STATIC (time_zones); static GHashTable/**/ *time_zones; -static guint -g_str_hash0 (gconstpointer data) -{ - return data ? g_str_hash (data) : 0; -} - -static gboolean -g_str_equal0 (gconstpointer a, - gconstpointer b) -{ - if (a == b) - return TRUE; - - if (!a || !b) - return FALSE; - - return g_str_equal (a, b); -} - /** * g_time_zone_unref: * @tz: a #GTimeZone @@ -166,9 +147,12 @@ g_time_zone_unref (GTimeZone *tz) if (g_atomic_int_dec_and_test (&tz->ref_count)) { - G_LOCK(time_zones); - g_hash_table_remove (time_zones, tz->name); - G_UNLOCK(time_zones); + if (tz->name != NULL) + { + G_LOCK(time_zones); + g_hash_table_remove (time_zones, tz->name); + G_UNLOCK(time_zones); + } if (tz->zoneinfo) g_buffer_unref (tz->zoneinfo); @@ -345,10 +329,13 @@ g_time_zone_new (const gchar *identifier) G_LOCK (time_zones); if (time_zones == NULL) - time_zones = g_hash_table_new (g_str_hash0, - g_str_equal0); + time_zones = g_hash_table_new (g_str_hash, g_str_equal); + + if (identifier) + tz = g_hash_table_lookup (time_zones, identifier); + else + tz = NULL; - tz = g_hash_table_lookup (time_zones, identifier); if (tz == NULL) { tz = g_slice_new0 (GTimeZone); @@ -412,7 +399,8 @@ g_time_zone_new (const gchar *identifier) } } - g_hash_table_insert (time_zones, tz->name, tz); + if (identifier) + g_hash_table_insert (time_zones, tz->name, tz); } g_atomic_int_inc (&tz->ref_count); G_UNLOCK (time_zones); -- 2.7.4