[libgweather] Move the timezone cache to GWeatherWorld
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather] Move the timezone cache to GWeatherWorld
- Date: Fri, 25 Oct 2013 15:09:12 +0000 (UTC)
commit 65943dabceb54d485f14dca03aa75412bdba559e
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Fri Oct 25 16:49:47 2013 +0200
Move the timezone cache to GWeatherWorld
Where it rightly belongs
libgweather/gweather-location.c | 2 ++
libgweather/gweather-timezone.c | 17 ++++-------------
libgweather/parser.c | 5 ++++-
libgweather/parser.h | 1 +
libgweather/weather-priv.h | 1 +
5 files changed, 12 insertions(+), 14 deletions(-)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 0b7da66..0dddbf5 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -382,6 +382,8 @@ gweather_location_unref (GWeatherLocation *loc)
if (loc->metar_code_cache)
g_hash_table_unref (loc->metar_code_cache);
+ if (loc->timezone_cache)
+ g_hash_table_unref (loc->timezone_cache);
g_slice_free (GWeatherLocation, loc);
}
diff --git a/libgweather/gweather-timezone.c b/libgweather/gweather-timezone.c
index c6c8b33..7a241b3 100644
--- a/libgweather/gweather-timezone.c
+++ b/libgweather/gweather-timezone.c
@@ -149,8 +149,6 @@ parse_tzdata (const char *tzname, time_t start, time_t end,
return TRUE;
}
-static GHashTable *timezones = NULL;
-
/**
* gweather_timezone_get_by_tzid:
* @tzid: A timezone identifier, like "America/New_York" or "Europe/London"
@@ -163,13 +161,11 @@ static GHashTable *timezones = NULL;
GWeatherTimezone *
gweather_timezone_get_by_tzid (const char *tzid)
{
- /* ensure that the database has been loaded and parsed */
- gweather_location_get_world ();
+ GWeatherLocation *world;
- if (timezones == NULL)
- return NULL;
+ world = gweather_location_get_world ();
- return g_hash_table_lookup (timezones, tzid);
+ return g_hash_table_lookup (world->timezone_cache, tzid);
}
static GWeatherTimezone *
@@ -219,12 +215,7 @@ parse_timezone (GWeatherParser *parser)
zone->has_dst = has_dst;
zone->dst_offset = dst_offset;
- if (timezones == NULL)
- timezones = g_hash_table_new_full (g_str_hash, g_str_equal,
- NULL, /* key owned by zone */
- (GDestroyNotify) gweather_timezone_unref);
-
- g_hash_table_insert (timezones, zone->id, zone);
+ g_hash_table_insert (parser->timezone_cache, zone->id, zone);
name = NULL;
}
diff --git a/libgweather/parser.c b/libgweather/parser.c
index 4397293..cda861a 100644
--- a/libgweather/parser.c
+++ b/libgweather/parser.c
@@ -183,7 +183,10 @@ _gweather_parser_new (void)
tm.tm_year++;
parser->year_end = mktime (&tm);
- parser->metar_code_cache = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
gweather_location_list_free);
+ parser->metar_code_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+ NULL, gweather_location_list_free);
+ parser->timezone_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+ NULL, (GDestroyNotify) gweather_timezone_unref);
return parser;
diff --git a/libgweather/parser.h b/libgweather/parser.h
index 5af49a5..2d5fa9f 100644
--- a/libgweather/parser.h
+++ b/libgweather/parser.h
@@ -28,6 +28,7 @@ typedef struct {
xmlTextReaderPtr xml;
time_t year_start, year_end;
GHashTable *metar_code_cache;
+ GHashTable *timezone_cache;
} GWeatherParser;
GWeatherParser *_gweather_parser_new (void);
diff --git a/libgweather/weather-priv.h b/libgweather/weather-priv.h
index c9e4b73..f81c228 100644
--- a/libgweather/weather-priv.h
+++ b/libgweather/weather-priv.h
@@ -47,6 +47,7 @@ struct _GWeatherLocation {
gboolean latlon_valid;
GWeatherTimezone **zones;
GHashTable *metar_code_cache;
+ GHashTable *timezone_cache;
int ref_count;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]