From ceb35b237bb7538c0defd3acc13f95af3081495e Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Sun, 15 Dec 2002 01:35:07 +0000 Subject: [PATCH] Break _g_locale_charset() into two pieces - a fast "raw" piece, and a slow Sat Dec 14 20:11:41 2002 Owen Taylor * glib/libcharset/{localcharset.[ch] libcharset-glib.patch} glib/gutf8.c: Break _g_locale_charset() into two pieces - a fast "raw" piece, and a slow "unalias pieces". Always call the "raw" piece, and call the unalias bit if it changes. Use a per-thread cache. (#79529) --- ChangeLog | 8 +++++ ChangeLog.pre-2-10 | 8 +++++ ChangeLog.pre-2-12 | 8 +++++ ChangeLog.pre-2-2 | 8 +++++ ChangeLog.pre-2-4 | 8 +++++ ChangeLog.pre-2-6 | 8 +++++ ChangeLog.pre-2-8 | 8 +++++ glib/gutf8.c | 56 ++++++++++++++++++++++++------- glib/libcharset/libcharset-glib.patch | 63 +++++++++++++++++++++++++---------- glib/libcharset/libcharset.h | 3 +- glib/libcharset/localcharset.c | 17 +++++++--- 11 files changed, 159 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7d8fdcb..f91117c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sat Dec 14 20:11:41 2002 Owen Taylor + + * glib/libcharset/{localcharset.[ch] libcharset-glib.patch} + glib/gutf8.c: Break _g_locale_charset() into two pieces + - a fast "raw" piece, and a slow "unalias pieces". + Always call the "raw" piece, and call the unalias bit + if it changes. Use a per-thread cache. (#79529) + 2002-12-15 Matthias Clasen * configure.in: Set TRIO_LIBS when building with trio. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 7d8fdcb..f91117c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +Sat Dec 14 20:11:41 2002 Owen Taylor + + * glib/libcharset/{localcharset.[ch] libcharset-glib.patch} + glib/gutf8.c: Break _g_locale_charset() into two pieces + - a fast "raw" piece, and a slow "unalias pieces". + Always call the "raw" piece, and call the unalias bit + if it changes. Use a per-thread cache. (#79529) + 2002-12-15 Matthias Clasen * configure.in: Set TRIO_LIBS when building with trio. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 7d8fdcb..f91117c 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +Sat Dec 14 20:11:41 2002 Owen Taylor + + * glib/libcharset/{localcharset.[ch] libcharset-glib.patch} + glib/gutf8.c: Break _g_locale_charset() into two pieces + - a fast "raw" piece, and a slow "unalias pieces". + Always call the "raw" piece, and call the unalias bit + if it changes. Use a per-thread cache. (#79529) + 2002-12-15 Matthias Clasen * configure.in: Set TRIO_LIBS when building with trio. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 7d8fdcb..f91117c 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,11 @@ +Sat Dec 14 20:11:41 2002 Owen Taylor + + * glib/libcharset/{localcharset.[ch] libcharset-glib.patch} + glib/gutf8.c: Break _g_locale_charset() into two pieces + - a fast "raw" piece, and a slow "unalias pieces". + Always call the "raw" piece, and call the unalias bit + if it changes. Use a per-thread cache. (#79529) + 2002-12-15 Matthias Clasen * configure.in: Set TRIO_LIBS when building with trio. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 7d8fdcb..f91117c 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +Sat Dec 14 20:11:41 2002 Owen Taylor + + * glib/libcharset/{localcharset.[ch] libcharset-glib.patch} + glib/gutf8.c: Break _g_locale_charset() into two pieces + - a fast "raw" piece, and a slow "unalias pieces". + Always call the "raw" piece, and call the unalias bit + if it changes. Use a per-thread cache. (#79529) + 2002-12-15 Matthias Clasen * configure.in: Set TRIO_LIBS when building with trio. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 7d8fdcb..f91117c 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +Sat Dec 14 20:11:41 2002 Owen Taylor + + * glib/libcharset/{localcharset.[ch] libcharset-glib.patch} + glib/gutf8.c: Break _g_locale_charset() into two pieces + - a fast "raw" piece, and a slow "unalias pieces". + Always call the "raw" piece, and call the unalias bit + if it changes. Use a per-thread cache. (#79529) + 2002-12-15 Matthias Clasen * configure.in: Set TRIO_LIBS when building with trio. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 7d8fdcb..f91117c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +Sat Dec 14 20:11:41 2002 Owen Taylor + + * glib/libcharset/{localcharset.[ch] libcharset-glib.patch} + glib/gutf8.c: Break _g_locale_charset() into two pieces + - a fast "raw" piece, and a slow "unalias pieces". + Always call the "raw" piece, and call the unalias bit + if it changes. Use a per-thread cache. (#79529) + 2002-12-15 Matthias Clasen * configure.in: Set TRIO_LIBS when building with trio. diff --git a/glib/gutf8.c b/glib/gutf8.c index 2ef0fd6..6b01a09 100644 --- a/glib/gutf8.c +++ b/glib/gutf8.c @@ -409,7 +409,8 @@ _g_charset_get_aliases (const char *canonical_name) } static gboolean -g_utf8_get_charset_internal (const char **a) +g_utf8_get_charset_internal (const char *raw_data, + const char **a) { const char *charset = getenv("CHARSET"); @@ -428,7 +429,7 @@ g_utf8_get_charset_internal (const char **a) * barrier, so we lock for it */ G_LOCK (aliases); - charset = _g_locale_charset (); + charset = _g_locale_charset_unalias (raw_data); G_UNLOCK (aliases); if (charset && *charset) @@ -447,8 +448,22 @@ g_utf8_get_charset_internal (const char **a) return FALSE; } -static int utf8_locale_cache = -1; -static const char *utf8_charset_cache = NULL; +typedef struct _GCharsetCache GCharsetCache; + +struct _GCharsetCache { + gboolean is_utf8; + gchar *raw; + gchar *charset; +}; + +static void +charset_cache_free (gpointer data) +{ + GCharsetCache *cache = data; + g_free (cache->raw); + g_free (cache->charset); + g_free (cache); +} /** * g_get_charset: @@ -471,16 +486,33 @@ static const char *utf8_charset_cache = NULL; gboolean g_get_charset (G_CONST_RETURN char **charset) { - if (utf8_locale_cache != -1) + static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT; + GCharsetCache *cache = g_static_private_get (&cache_private); + const gchar *raw; + + if (!cache) { - if (charset) - *charset = utf8_charset_cache; - return utf8_locale_cache; + cache = g_new0 (GCharsetCache, 1); + g_static_private_set (&cache_private, cache, charset_cache_free); } - utf8_locale_cache = g_utf8_get_charset_internal (&utf8_charset_cache); - if (charset) - *charset = utf8_charset_cache; - return utf8_locale_cache; + + raw = _g_locale_charset_raw (); + + if (!(cache->raw && strcmp (cache->raw, raw) == 0)) + { + const gchar *new_charset; + + g_free (cache->raw); + g_free (cache->charset); + cache->raw = g_strdup (raw); + cache->is_utf8 = g_utf8_get_charset_internal (raw, &new_charset); + cache->charset = g_strdup (new_charset); + } + + if (charset) + *charset = cache->charset; + + return cache->is_utf8; } /* unicode_strchr */ diff --git a/glib/libcharset/libcharset-glib.patch b/glib/libcharset/libcharset-glib.patch index c1069ab..c48910a 100644 --- a/glib/libcharset/libcharset-glib.patch +++ b/glib/libcharset/libcharset-glib.patch @@ -1,7 +1,7 @@ -# Patch against libcharset version 1.1 ---- /home/otaylor/ftp/libiconv-1.7.0.1/libcharset/lib/localcharset.c Wed Aug 8 08:52:28 2001 -+++ localcharset.c Wed Sep 26 22:47:38 2001 -@@ -83,8 +83,8 @@ +diff -ur libcharset/localcharset.c /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/localcharset.c +--- libcharset/localcharset.c Sat Dec 14 20:04:44 2002 ++++ /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/localcharset.c Sat Dec 14 20:09:45 2002 +@@ -102,8 +102,8 @@ static const char * volatile charset_aliases; /* Return a pointer to the contents of the charset.alias file. */ @@ -12,16 +12,39 @@ { const char *cp; -@@ -205,7 +205,7 @@ - STATIC - #endif +@@ -235,14 +235,10 @@ + If the canonical name cannot be determined, the result is a non-canonical + name. */ + +-#ifdef STATIC +-STATIC +-#endif const char * -locale_charset () -+_g_locale_charset () ++_g_locale_charset_raw () { const char *codeset; - const char *aliases; -@@ -262,7 +262,7 @@ +- const char *aliases; + + #if !(defined WIN32 || defined OS2) + +@@ -344,12 +340,23 @@ + + #endif + ++ return codeset; ++} ++ ++#ifdef STATIC ++STATIC ++#endif ++const char * ++_g_locale_charset_unalias (const char *codeset) ++{ ++ const char *aliases; ++ + if (codeset == NULL) + /* The canonical name cannot be determined. */ codeset = ""; /* Resolve alias. */ @@ -30,8 +53,9 @@ *aliases != '\0'; aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) if (strcmp (codeset, aliases) == 0 ---- /home/otaylor/ftp/libiconv-1.7.0.1/libcharset/m4/glibc21.m4 Sat Jun 17 14:31:21 2000 -+++ glibc21.m4 Fri Sep 28 12:12:39 2001 +diff -ur libcharset/glibc21.m4 /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/glibc21.m4 +--- libcharset/glibc21.m4 Sat Dec 14 20:04:44 2002 ++++ /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/glibc21.m4 Fri Sep 28 19:44:46 2001 @@ -3,7 +3,7 @@ # Test for the GNU C Library, version 2.1 or newer. # From Bruno Haible. @@ -41,8 +65,9 @@ [ AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer, ac_cv_gnu_library_2_1, ---- /home/otaylor/ftp/libiconv-1.7.0.1/libcharset/m4/codeset.m4 Mon Apr 3 04:06:24 2000 -+++ codeset.m4 Fri Sep 28 12:12:44 2001 +diff -ur libcharset/codeset.m4 /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/codeset.m4 +--- libcharset/codeset.m4 Sat Dec 14 20:04:44 2002 ++++ /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/codeset.m4 Fri Sep 28 19:44:46 2001 @@ -2,7 +2,7 @@ dnl From Bruno Haible. @@ -52,15 +77,17 @@ [ AC_CHECK_HEADERS(langinfo.h) AC_CHECK_FUNCS(nl_langinfo) ---- /home/otaylor/ftp/libiconv-1.7.0.1/libcharset/include/libcharset.h.in Tue Mar 27 08:34:42 2001 -+++ libcharset.h Wed Sep 26 21:55:40 2001 -@@ -30,8 +30,8 @@ +diff -ur libcharset/libcharset.h /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/libcharset.h +--- libcharset/libcharset.h Sat Dec 14 20:04:44 2002 ++++ /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/libcharset.h Sat Dec 14 19:03:11 2002 +@@ -30,8 +30,9 @@ The result must not be freed; it is statically allocated. If the canonical name cannot be determined, the result is a non-canonical name. */ -extern const char * locale_charset (void); - -+extern const char * _g_locale_charset (void); ++extern const char * _g_locale_charset_raw (void); ++extern const char * _g_locale_charset_unalias (const char *codeset); +extern const char * _g_locale_get_charset_aliases (void); #ifdef __cplusplus diff --git a/glib/libcharset/libcharset.h b/glib/libcharset/libcharset.h index ba4c6bd..3af1d17 100644 --- a/glib/libcharset/libcharset.h +++ b/glib/libcharset/libcharset.h @@ -30,7 +30,8 @@ extern "C" { The result must not be freed; it is statically allocated. If the canonical name cannot be determined, the result is a non-canonical name. */ -extern const char * _g_locale_charset (void); +extern const char * _g_locale_charset_raw (void); +extern const char * _g_locale_charset_unalias (const char *codeset); extern const char * _g_locale_get_charset_aliases (void); #ifdef __cplusplus diff --git a/glib/libcharset/localcharset.c b/glib/libcharset/localcharset.c index 078ee32..7c5dde9 100644 --- a/glib/libcharset/localcharset.c +++ b/glib/libcharset/localcharset.c @@ -235,14 +235,10 @@ _g_locale_get_charset_aliases () If the canonical name cannot be determined, the result is a non-canonical name. */ -#ifdef STATIC -STATIC -#endif const char * -_g_locale_charset () +_g_locale_charset_raw () { const char *codeset; - const char *aliases; #if !(defined WIN32 || defined OS2) @@ -344,6 +340,17 @@ _g_locale_charset () #endif + return codeset; +} + +#ifdef STATIC +STATIC +#endif +const char * +_g_locale_charset_unalias (const char *codeset) +{ + const char *aliases; + if (codeset == NULL) /* The canonical name cannot be determined. */ codeset = ""; -- 2.7.4