diff options
author | Matthias Clasen <mclasen@redhat.com> | 2005-11-04 22:27:04 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2005-11-04 22:27:04 +0000 |
commit | e9852a17beb660e7fc2f512f8230152ecb5fff91 (patch) | |
tree | bf364de982dbb772bad63cfb6e9de07edce7e403 /glib/guniprop.c | |
parent | 1e6a75dbc45e5f4eeb0a4c1f0f7913360406a653 (diff) | |
download | glib-e9852a17beb660e7fc2f512f8230152ecb5fff91.tar.gz |
Apply a patch from Behdad Esfahbod to use a faster lookup table for
2005-11-04 Matthias Clasen <mclasen@redhat.com>
* glib/Makefile.am: Apply a patch from Behdad Esfahbod to
use a faster lookup table for g_unichar_get_mirror_char().
* glib/gmirroringtable.h: The new table.
* glib/gunichartables.h: Remove bidi_mirroring_table.
* glib/gen-unicode-tables.pl: Don't generate the mirroring
table.
* glib/glib-mirroring-tab/*: Sources for the program
which generated gmirroringtable.h.
* glib/glist.c: Avoid some code duplication.
Diffstat (limited to 'glib/guniprop.c')
-rw-r--r-- | glib/guniprop.c | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/glib/guniprop.c b/glib/guniprop.c index 6c88a27c4..02cd0e2b7 100644 --- a/glib/guniprop.c +++ b/glib/guniprop.c @@ -27,6 +27,7 @@ #include "glib.h" #include "gunichartables.h" +#include "gmirroringtable.h" #include "gunicodeprivate.h" #include "galias.h" @@ -1007,50 +1008,26 @@ g_utf8_casefold (const gchar *str, * * If @ch has the Unicode mirrored property and there is another unicode * character that typically has a glyph that is the mirror image of @ch's - * glyph, puts that character in the address pointed to by @mirrored_ch. + * glyph and @mirrored_ch is set, it puts that character in the address + * pointed to by @mirrored_ch. Otherwise the original character is put. * - * Return value: %TRUE if @ch has a mirrored character and @mirrored_ch is - * filled in, %FALSE otherwise + * Return value: %TRUE if @ch has a mirrored character, %FALSE otherwise * * Since: 2.4 **/ -/* This code is adapted from FriBidi (http://fribidi.sourceforge.net/). - * FriBidi is: Copyright (C) 1999,2000 Dov Grobgeld, and - * Copyright (C) 2001,2002 Behdad Esfahbod. - */ gboolean g_unichar_get_mirror_char (gunichar ch, gunichar *mirrored_ch) { gint pos, step, size; gboolean found; + gunichar mirrored; - size = G_N_ELEMENTS (bidi_mirroring_table); - pos = step = (size / 2) + 1; - - while (step > 1) - { - gunichar cmp_ch = bidi_mirroring_table[pos].ch; - step = (step + 1) / 2; + mirrored = GLIB_GET_MIRRORING(ch); - if (cmp_ch < ch) - { - pos += step; - if (pos > size - 1) - pos = size - 1; - } - else if (cmp_ch > ch) - { - pos -= step; - if (pos < 0) - pos = 0; - } - else - break; - } - found = bidi_mirroring_table[pos].ch == ch; + found = ch != mirrored; if (mirrored_ch) - *mirrored_ch = found ? bidi_mirroring_table[pos].mirrored_ch : ch; + *mirrored_ch = mirrored; return found; |