Break _g_locale_charset() into two pieces - a fast "raw" piece, and a slow

Sat Dec 14 20:11:41 2002  Owen Taylor  <otaylor@redhat.com>

        * 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)
This commit is contained in:
Owen Taylor 2002-12-15 01:35:07 +00:00 committed by Owen Taylor
parent c95ce4b301
commit ceb35b237b
11 changed files with 159 additions and 36 deletions

View File

@ -1,3 +1,11 @@
Sat Dec 14 20:11:41 2002 Owen Taylor <otaylor@redhat.com>
* 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 <maclas@gmx.de> 2002-12-15 Matthias Clasen <maclas@gmx.de>
* configure.in: Set TRIO_LIBS when building with trio. * configure.in: Set TRIO_LIBS when building with trio.

View File

@ -1,3 +1,11 @@
Sat Dec 14 20:11:41 2002 Owen Taylor <otaylor@redhat.com>
* 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 <maclas@gmx.de> 2002-12-15 Matthias Clasen <maclas@gmx.de>
* configure.in: Set TRIO_LIBS when building with trio. * configure.in: Set TRIO_LIBS when building with trio.

View File

@ -1,3 +1,11 @@
Sat Dec 14 20:11:41 2002 Owen Taylor <otaylor@redhat.com>
* 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 <maclas@gmx.de> 2002-12-15 Matthias Clasen <maclas@gmx.de>
* configure.in: Set TRIO_LIBS when building with trio. * configure.in: Set TRIO_LIBS when building with trio.

View File

@ -1,3 +1,11 @@
Sat Dec 14 20:11:41 2002 Owen Taylor <otaylor@redhat.com>
* 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 <maclas@gmx.de> 2002-12-15 Matthias Clasen <maclas@gmx.de>
* configure.in: Set TRIO_LIBS when building with trio. * configure.in: Set TRIO_LIBS when building with trio.

View File

@ -1,3 +1,11 @@
Sat Dec 14 20:11:41 2002 Owen Taylor <otaylor@redhat.com>
* 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 <maclas@gmx.de> 2002-12-15 Matthias Clasen <maclas@gmx.de>
* configure.in: Set TRIO_LIBS when building with trio. * configure.in: Set TRIO_LIBS when building with trio.

View File

@ -1,3 +1,11 @@
Sat Dec 14 20:11:41 2002 Owen Taylor <otaylor@redhat.com>
* 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 <maclas@gmx.de> 2002-12-15 Matthias Clasen <maclas@gmx.de>
* configure.in: Set TRIO_LIBS when building with trio. * configure.in: Set TRIO_LIBS when building with trio.

View File

@ -1,3 +1,11 @@
Sat Dec 14 20:11:41 2002 Owen Taylor <otaylor@redhat.com>
* 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 <maclas@gmx.de> 2002-12-15 Matthias Clasen <maclas@gmx.de>
* configure.in: Set TRIO_LIBS when building with trio. * configure.in: Set TRIO_LIBS when building with trio.

View File

@ -409,7 +409,8 @@ _g_charset_get_aliases (const char *canonical_name)
} }
static gboolean 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"); const char *charset = getenv("CHARSET");
@ -428,7 +429,7 @@ g_utf8_get_charset_internal (const char **a)
* barrier, so we lock for it * barrier, so we lock for it
*/ */
G_LOCK (aliases); G_LOCK (aliases);
charset = _g_locale_charset (); charset = _g_locale_charset_unalias (raw_data);
G_UNLOCK (aliases); G_UNLOCK (aliases);
if (charset && *charset) if (charset && *charset)
@ -447,8 +448,22 @@ g_utf8_get_charset_internal (const char **a)
return FALSE; return FALSE;
} }
static int utf8_locale_cache = -1; typedef struct _GCharsetCache GCharsetCache;
static const char *utf8_charset_cache = NULL;
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: * g_get_charset:
@ -471,16 +486,33 @@ static const char *utf8_charset_cache = NULL;
gboolean gboolean
g_get_charset (G_CONST_RETURN char **charset) 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) cache = g_new0 (GCharsetCache, 1);
*charset = utf8_charset_cache; g_static_private_set (&cache_private, cache, charset_cache_free);
return utf8_locale_cache;
} }
utf8_locale_cache = g_utf8_get_charset_internal (&utf8_charset_cache);
if (charset) raw = _g_locale_charset_raw ();
*charset = utf8_charset_cache;
return utf8_locale_cache; 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 */ /* unicode_strchr */

View File

@ -1,7 +1,7 @@
# Patch against libcharset version 1.1 diff -ur libcharset/localcharset.c /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/localcharset.c
--- /home/otaylor/ftp/libiconv-1.7.0.1/libcharset/lib/localcharset.c Wed Aug 8 08:52:28 2001 --- libcharset/localcharset.c Sat Dec 14 20:04:44 2002
+++ localcharset.c Wed Sep 26 22:47:38 2001 +++ /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/localcharset.c Sat Dec 14 20:09:45 2002
@@ -83,8 +83,8 @@ @@ -102,8 +102,8 @@
static const char * volatile charset_aliases; static const char * volatile charset_aliases;
/* Return a pointer to the contents of the charset.alias file. */ /* Return a pointer to the contents of the charset.alias file. */
@ -12,16 +12,39 @@
{ {
const char *cp; const char *cp;
@@ -205,7 +205,7 @@ @@ -235,14 +235,10 @@
STATIC If the canonical name cannot be determined, the result is a non-canonical
#endif name. */
-#ifdef STATIC
-STATIC
-#endif
const char * const char *
-locale_charset () -locale_charset ()
+_g_locale_charset () +_g_locale_charset_raw ()
{ {
const char *codeset; const char *codeset;
const char *aliases; - const char *aliases;
@@ -262,7 +262,7 @@
#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 = ""; codeset = "";
/* Resolve alias. */ /* Resolve alias. */
@ -30,8 +53,9 @@
*aliases != '\0'; *aliases != '\0';
aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
if (strcmp (codeset, aliases) == 0 if (strcmp (codeset, aliases) == 0
--- /home/otaylor/ftp/libiconv-1.7.0.1/libcharset/m4/glibc21.m4 Sat Jun 17 14:31:21 2000 diff -ur libcharset/glibc21.m4 /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/glibc21.m4
+++ glibc21.m4 Fri Sep 28 12:12:39 2001 --- 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 @@ @@ -3,7 +3,7 @@
# Test for the GNU C Library, version 2.1 or newer. # Test for the GNU C Library, version 2.1 or newer.
# From Bruno Haible. # From Bruno Haible.
@ -41,8 +65,9 @@
[ [
AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer, AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer,
ac_cv_gnu_library_2_1, 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 diff -ur libcharset/codeset.m4 /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/codeset.m4
+++ codeset.m4 Fri Sep 28 12:12:44 2001 --- 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 @@ @@ -2,7 +2,7 @@
dnl From Bruno Haible. dnl From Bruno Haible.
@ -52,15 +77,17 @@
[ [
AC_CHECK_HEADERS(langinfo.h) AC_CHECK_HEADERS(langinfo.h)
AC_CHECK_FUNCS(nl_langinfo) 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 diff -ur libcharset/libcharset.h /home/otaylor/cvs/gnome2/glib-head/glib/libcharset/libcharset.h
+++ libcharset.h Wed Sep 26 21:55:40 2001 --- libcharset/libcharset.h Sat Dec 14 20:04:44 2002
@@ -30,8 +30,8 @@ +++ /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. The result must not be freed; it is statically allocated.
If the canonical name cannot be determined, the result is a non-canonical If the canonical name cannot be determined, the result is a non-canonical
name. */ name. */
-extern const char * locale_charset (void); -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); +extern const char * _g_locale_get_charset_aliases (void);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -30,7 +30,8 @@ extern "C" {
The result must not be freed; it is statically allocated. The result must not be freed; it is statically allocated.
If the canonical name cannot be determined, the result is a non-canonical If the canonical name cannot be determined, the result is a non-canonical
name. */ 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); extern const char * _g_locale_get_charset_aliases (void);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -235,14 +235,10 @@ _g_locale_get_charset_aliases ()
If the canonical name cannot be determined, the result is a non-canonical If the canonical name cannot be determined, the result is a non-canonical
name. */ name. */
#ifdef STATIC
STATIC
#endif
const char * const char *
_g_locale_charset () _g_locale_charset_raw ()
{ {
const char *codeset; const char *codeset;
const char *aliases;
#if !(defined WIN32 || defined OS2) #if !(defined WIN32 || defined OS2)
@ -344,6 +340,17 @@ _g_locale_charset ()
#endif #endif
return codeset;
}
#ifdef STATIC
STATIC
#endif
const char *
_g_locale_charset_unalias (const char *codeset)
{
const char *aliases;
if (codeset == NULL) if (codeset == NULL)
/* The canonical name cannot be determined. */ /* The canonical name cannot be determined. */
codeset = ""; codeset = "";