[glib: 1/2] gtimezone: Tidy up UTC timezone creation
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] gtimezone: Tidy up UTC timezone creation
- Date: Mon, 24 Feb 2020 11:47:18 +0000 (UTC)
commit a8ef5fdf8a5847848ecf1006ff03b8e54713d4df
Author: Philip Withnall <withnall endlessm com>
Date: Fri Oct 25 18:32:48 2019 +0100
gtimezone: Tidy up UTC timezone creation
Move the separate function inline using g_once_init_{enter,leave}(),
rather than g_once().
This marginally improves performance, taking 0.39s to create 10000000
UTC timezones, rather than 0.43s previously. (Who cares?)
Follow-up to !1105.
Signed-off-by: Philip Withnall <withnall endlessm com>
glib/gtimezone.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
---
diff --git a/glib/gtimezone.c b/glib/gtimezone.c
index 0155a5841..5a835dea9 100644
--- a/glib/gtimezone.c
+++ b/glib/gtimezone.c
@@ -1676,20 +1676,19 @@ g_time_zone_new (const gchar *identifier)
*
* Since: 2.26
**/
-static gpointer
-g_time_zone_utc_init (gpointer data)
-{
- return g_time_zone_new ("UTC");
-}
-
GTimeZone *
g_time_zone_new_utc (void)
{
- static GOnce utc_once = G_ONCE_INIT;
+ static GTimeZone *utc = NULL;
+ static gsize initialised;
- g_once (&utc_once, g_time_zone_utc_init, NULL);
+ if (g_once_init_enter (&initialised))
+ {
+ utc = g_time_zone_new ("UTC");
+ g_once_init_leave (&initialised, TRUE);
+ }
- return g_time_zone_ref ((GTimeZone *)utc_once.retval);
+ return g_time_zone_ref (utc);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]