From: Matthias Clasen Date: Fri, 4 Nov 2005 22:27:04 +0000 (+0000) Subject: Apply a patch from Behdad Esfahbod to use a faster lookup table for X-Git-Tag: GLIB_2_9_0~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e9852a17beb660e7fc2f512f8230152ecb5fff91;p=platform%2Fupstream%2Fglib.git Apply a patch from Behdad Esfahbod to use a faster lookup table for 2005-11-04 Matthias Clasen * 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. --- diff --git a/ChangeLog b/ChangeLog index 803625a..34014fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2005-11-04 Matthias Clasen + * 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. + * glib/gscanner.h: Include gdataset.h. (#320322) * glib/gdebug.h: add new GDebugFlag for fatal_criticals diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 803625a..34014fd 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,16 @@ 2005-11-04 Matthias Clasen + * 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. + * glib/gscanner.h: Include gdataset.h. (#320322) * glib/gdebug.h: add new GDebugFlag for fatal_criticals diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 803625a..34014fd 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,5 +1,16 @@ 2005-11-04 Matthias Clasen + * 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. + * glib/gscanner.h: Include gdataset.h. (#320322) * glib/gdebug.h: add new GDebugFlag for fatal_criticals diff --git a/glib/Makefile.am b/glib/Makefile.am index 72f2dc5..1df9003 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -30,13 +30,20 @@ endif BUILT_SOURCES = galias.h galiasdef.c +MIRRORING_TAB_SOURCES = \ + glib-mirroring-tab/Makefile \ + glib-mirroring-tab/gen-mirroring-tab.c \ + glib-mirroring-tab/packtab.h \ + glib-mirroring-tab/packtab.c + EXTRA_DIST = \ makefile.msc.in \ glib.rc.in \ gen-unicode-tables.pl \ makegalias.pl \ abicheck.sh \ - glib.symbols + glib.symbols \ + $(MIRRORING_TAB_SOURCES) # These may be in the builddir too BUILT_EXTRA_DIST = \ @@ -86,6 +93,7 @@ libglib_2_0_la_SOURCES = \ gmarkup.c \ gmem.c \ gmessages.c \ + gmirroringtable.h \ gnode.c \ goption.c \ gpattern.c \ diff --git a/glib/gen-unicode-tables.pl b/glib/gen-unicode-tables.pl index d6ccc2a..5368adf 100755 --- a/glib/gen-unicode-tables.pl +++ b/glib/gen-unicode-tables.pl @@ -176,7 +176,7 @@ if (@ARGV != 2) { die "\nUsage: $0 [-decomp | -both] UNICODE-VERSION DIRECTORY\n\n DIRECTORY should contain the following Unicode data files:\n UnicodeData.txt, LineBreak.txt, SpecialCasing.txt, CaseFolding.txt,\n CompositionExclusions.txt, BidiMirroring.txt\n\n"; } -my ($unicodedatatxt, $linebreaktxt, $specialcasingtxt, $casefoldingtxt, $compositionexclusionstxt, $bidimirroringtxt); +my ($unicodedatatxt, $linebreaktxt, $specialcasingtxt, $casefoldingtxt, $compositionexclusionstxt); my $d = $ARGV[1]; opendir (my $dir, $d) or die "Cannot open Unicode data dir $d: $!\n"; @@ -187,7 +187,6 @@ for my $f (readdir ($dir)) $specialcasingtxt = "$d/$f" if ($f =~ /SpecialCasing.*\.txt/); $casefoldingtxt = "$d/$f" if ($f =~ /CaseFolding.*\.txt/); $compositionexclusionstxt = "$d/$f" if ($f =~ /CompositionExclusions.*\.txt/); - $bidimirroringtxt = "$d/$f" if ($f =~ /BidiMirroring.*\.txt/); } defined $unicodedatatxt or die "Did not find UnicodeData file"; @@ -195,7 +194,6 @@ defined $linebreaktxt or die "Did not find LineBreak file"; defined $specialcasingtxt or die "Did not find SpecialCasing file"; defined $casefoldingtxt or die "Did not find CaseFolding file"; defined $compositionexclusionstxt or die "Did not find CompositionExclusions file"; -defined $bidimirroringtxt or die "Did not find BidiMirroring file"; print "Creating decomp table\n" if ($do_decomp); print "Creating property table\n" if ($do_props); @@ -486,23 +484,6 @@ while () close INPUT; -open (INPUT, "< $bidimirroringtxt") || exit 1; - -my @bidimirror; -while () -{ - chomp; - - next if /^#/; - next if /^\s*$/; - - s/\s*#.*//; - - @fields = split ('\s*;\s*', $_, 30); - - push @bidimirror, [hex ($fields[0]), hex ($fields[1])]; -} - if ($do_props) { &print_tables ($last_code) } @@ -679,21 +660,6 @@ sub print_tables &output_special_case_table (\*OUT); &output_casefold_table (\*OUT); - print OUT "static const struct {\n"; - print OUT " gunichar ch;\n"; - print OUT " gunichar mirrored_ch;\n"; - print OUT "} bidi_mirroring_table[] =\n"; - print OUT "{\n"; - $first = 1; - foreach $item (@bidimirror) - { - print OUT ",\n" unless $first; - $first = 0; - printf OUT " { 0x%04x, 0x%04x }", $item->[0], $item->[1]; - $bytes_out += 8; - } - print OUT "\n};\n\n"; - print OUT "#endif /* CHARTABLES_H */\n"; close (OUT); diff --git a/glib/glist.c b/glib/glist.c index 45799a5..1e9a96f 100644 --- a/glib/glist.c +++ b/glib/glist.c @@ -568,19 +568,16 @@ g_list_sort_merge (GList *l1, if (cmp <= 0) { l->next = l1; - l = l->next; - l->prev = lprev; - lprev = l; l1 = l1->next; } else { l->next = l2; - l = l->next; - l->prev = lprev; - lprev = l; l2 = l2->next; } + l = l->next; + l->prev = lprev; + lprev = l; } l->next = l1 ? l1 : l2; l->next->prev = l; diff --git a/glib/gunichartables.h b/glib/gunichartables.h index 27dc691..0df096a 100644 --- a/glib/gunichartables.h +++ b/glib/gunichartables.h @@ -11759,343 +11759,4 @@ static const struct { { 0xfb17, "\xd5\xb4\xd5\xad" }, }; -static const struct { - gunichar ch; - gunichar mirrored_ch; -} bidi_mirroring_table[] = -{ - { 0x0028, 0x0029 }, - { 0x0029, 0x0028 }, - { 0x003c, 0x003e }, - { 0x003e, 0x003c }, - { 0x005b, 0x005d }, - { 0x005d, 0x005b }, - { 0x007b, 0x007d }, - { 0x007d, 0x007b }, - { 0x00ab, 0x00bb }, - { 0x00bb, 0x00ab }, - { 0x2039, 0x203a }, - { 0x203a, 0x2039 }, - { 0x2045, 0x2046 }, - { 0x2046, 0x2045 }, - { 0x207d, 0x207e }, - { 0x207e, 0x207d }, - { 0x208d, 0x208e }, - { 0x208e, 0x208d }, - { 0x2208, 0x220b }, - { 0x2209, 0x220c }, - { 0x220a, 0x220d }, - { 0x220b, 0x2208 }, - { 0x220c, 0x2209 }, - { 0x220d, 0x220a }, - { 0x2215, 0x29f5 }, - { 0x223c, 0x223d }, - { 0x223d, 0x223c }, - { 0x2243, 0x22cd }, - { 0x2252, 0x2253 }, - { 0x2253, 0x2252 }, - { 0x2254, 0x2255 }, - { 0x2255, 0x2254 }, - { 0x2264, 0x2265 }, - { 0x2265, 0x2264 }, - { 0x2266, 0x2267 }, - { 0x2267, 0x2266 }, - { 0x2268, 0x2269 }, - { 0x2269, 0x2268 }, - { 0x226a, 0x226b }, - { 0x226b, 0x226a }, - { 0x226e, 0x226f }, - { 0x226f, 0x226e }, - { 0x2270, 0x2271 }, - { 0x2271, 0x2270 }, - { 0x2272, 0x2273 }, - { 0x2273, 0x2272 }, - { 0x2274, 0x2275 }, - { 0x2275, 0x2274 }, - { 0x2276, 0x2277 }, - { 0x2277, 0x2276 }, - { 0x2278, 0x2279 }, - { 0x2279, 0x2278 }, - { 0x227a, 0x227b }, - { 0x227b, 0x227a }, - { 0x227c, 0x227d }, - { 0x227d, 0x227c }, - { 0x227e, 0x227f }, - { 0x227f, 0x227e }, - { 0x2280, 0x2281 }, - { 0x2281, 0x2280 }, - { 0x2282, 0x2283 }, - { 0x2283, 0x2282 }, - { 0x2284, 0x2285 }, - { 0x2285, 0x2284 }, - { 0x2286, 0x2287 }, - { 0x2287, 0x2286 }, - { 0x2288, 0x2289 }, - { 0x2289, 0x2288 }, - { 0x228a, 0x228b }, - { 0x228b, 0x228a }, - { 0x228f, 0x2290 }, - { 0x2290, 0x228f }, - { 0x2291, 0x2292 }, - { 0x2292, 0x2291 }, - { 0x2298, 0x29b8 }, - { 0x22a2, 0x22a3 }, - { 0x22a3, 0x22a2 }, - { 0x22a6, 0x2ade }, - { 0x22a8, 0x2ae4 }, - { 0x22a9, 0x2ae3 }, - { 0x22ab, 0x2ae5 }, - { 0x22b0, 0x22b1 }, - { 0x22b1, 0x22b0 }, - { 0x22b2, 0x22b3 }, - { 0x22b3, 0x22b2 }, - { 0x22b4, 0x22b5 }, - { 0x22b5, 0x22b4 }, - { 0x22b6, 0x22b7 }, - { 0x22b7, 0x22b6 }, - { 0x22c9, 0x22ca }, - { 0x22ca, 0x22c9 }, - { 0x22cb, 0x22cc }, - { 0x22cc, 0x22cb }, - { 0x22cd, 0x2243 }, - { 0x22d0, 0x22d1 }, - { 0x22d1, 0x22d0 }, - { 0x22d6, 0x22d7 }, - { 0x22d7, 0x22d6 }, - { 0x22d8, 0x22d9 }, - { 0x22d9, 0x22d8 }, - { 0x22da, 0x22db }, - { 0x22db, 0x22da }, - { 0x22dc, 0x22dd }, - { 0x22dd, 0x22dc }, - { 0x22de, 0x22df }, - { 0x22df, 0x22de }, - { 0x22e0, 0x22e1 }, - { 0x22e1, 0x22e0 }, - { 0x22e2, 0x22e3 }, - { 0x22e3, 0x22e2 }, - { 0x22e4, 0x22e5 }, - { 0x22e5, 0x22e4 }, - { 0x22e6, 0x22e7 }, - { 0x22e7, 0x22e6 }, - { 0x22e8, 0x22e9 }, - { 0x22e9, 0x22e8 }, - { 0x22ea, 0x22eb }, - { 0x22eb, 0x22ea }, - { 0x22ec, 0x22ed }, - { 0x22ed, 0x22ec }, - { 0x22f0, 0x22f1 }, - { 0x22f1, 0x22f0 }, - { 0x22f2, 0x22fa }, - { 0x22f3, 0x22fb }, - { 0x22f4, 0x22fc }, - { 0x22f6, 0x22fd }, - { 0x22f7, 0x22fe }, - { 0x22fa, 0x22f2 }, - { 0x22fb, 0x22f3 }, - { 0x22fc, 0x22f4 }, - { 0x22fd, 0x22f6 }, - { 0x22fe, 0x22f7 }, - { 0x2308, 0x2309 }, - { 0x2309, 0x2308 }, - { 0x230a, 0x230b }, - { 0x230b, 0x230a }, - { 0x2329, 0x232a }, - { 0x232a, 0x2329 }, - { 0x2768, 0x2769 }, - { 0x2769, 0x2768 }, - { 0x276a, 0x276b }, - { 0x276b, 0x276a }, - { 0x276c, 0x276d }, - { 0x276d, 0x276c }, - { 0x276e, 0x276f }, - { 0x276f, 0x276e }, - { 0x2770, 0x2771 }, - { 0x2771, 0x2770 }, - { 0x2772, 0x2773 }, - { 0x2773, 0x2772 }, - { 0x2774, 0x2775 }, - { 0x2775, 0x2774 }, - { 0x27c3, 0x27c4 }, - { 0x27c4, 0x27c3 }, - { 0x27c5, 0x27c6 }, - { 0x27c6, 0x27c5 }, - { 0x27d5, 0x27d6 }, - { 0x27d6, 0x27d5 }, - { 0x27dd, 0x27de }, - { 0x27de, 0x27dd }, - { 0x27e2, 0x27e3 }, - { 0x27e3, 0x27e2 }, - { 0x27e4, 0x27e5 }, - { 0x27e5, 0x27e4 }, - { 0x27e6, 0x27e7 }, - { 0x27e7, 0x27e6 }, - { 0x27e8, 0x27e9 }, - { 0x27e9, 0x27e8 }, - { 0x27ea, 0x27eb }, - { 0x27eb, 0x27ea }, - { 0x2983, 0x2984 }, - { 0x2984, 0x2983 }, - { 0x2985, 0x2986 }, - { 0x2986, 0x2985 }, - { 0x2987, 0x2988 }, - { 0x2988, 0x2987 }, - { 0x2989, 0x298a }, - { 0x298a, 0x2989 }, - { 0x298b, 0x298c }, - { 0x298c, 0x298b }, - { 0x298d, 0x2990 }, - { 0x298e, 0x298f }, - { 0x298f, 0x298e }, - { 0x2990, 0x298d }, - { 0x2991, 0x2992 }, - { 0x2992, 0x2991 }, - { 0x2993, 0x2994 }, - { 0x2994, 0x2993 }, - { 0x2995, 0x2996 }, - { 0x2996, 0x2995 }, - { 0x2997, 0x2998 }, - { 0x2998, 0x2997 }, - { 0x29b8, 0x2298 }, - { 0x29c0, 0x29c1 }, - { 0x29c1, 0x29c0 }, - { 0x29c4, 0x29c5 }, - { 0x29c5, 0x29c4 }, - { 0x29cf, 0x29d0 }, - { 0x29d0, 0x29cf }, - { 0x29d1, 0x29d2 }, - { 0x29d2, 0x29d1 }, - { 0x29d4, 0x29d5 }, - { 0x29d5, 0x29d4 }, - { 0x29d8, 0x29d9 }, - { 0x29d9, 0x29d8 }, - { 0x29da, 0x29db }, - { 0x29db, 0x29da }, - { 0x29f5, 0x2215 }, - { 0x29f8, 0x29f9 }, - { 0x29f9, 0x29f8 }, - { 0x29fc, 0x29fd }, - { 0x29fd, 0x29fc }, - { 0x2a2b, 0x2a2c }, - { 0x2a2c, 0x2a2b }, - { 0x2a2d, 0x2a2e }, - { 0x2a2e, 0x2a2d }, - { 0x2a34, 0x2a35 }, - { 0x2a35, 0x2a34 }, - { 0x2a3c, 0x2a3d }, - { 0x2a3d, 0x2a3c }, - { 0x2a64, 0x2a65 }, - { 0x2a65, 0x2a64 }, - { 0x2a79, 0x2a7a }, - { 0x2a7a, 0x2a79 }, - { 0x2a7d, 0x2a7e }, - { 0x2a7e, 0x2a7d }, - { 0x2a7f, 0x2a80 }, - { 0x2a80, 0x2a7f }, - { 0x2a81, 0x2a82 }, - { 0x2a82, 0x2a81 }, - { 0x2a83, 0x2a84 }, - { 0x2a84, 0x2a83 }, - { 0x2a8b, 0x2a8c }, - { 0x2a8c, 0x2a8b }, - { 0x2a91, 0x2a92 }, - { 0x2a92, 0x2a91 }, - { 0x2a93, 0x2a94 }, - { 0x2a94, 0x2a93 }, - { 0x2a95, 0x2a96 }, - { 0x2a96, 0x2a95 }, - { 0x2a97, 0x2a98 }, - { 0x2a98, 0x2a97 }, - { 0x2a99, 0x2a9a }, - { 0x2a9a, 0x2a99 }, - { 0x2a9b, 0x2a9c }, - { 0x2a9c, 0x2a9b }, - { 0x2aa1, 0x2aa2 }, - { 0x2aa2, 0x2aa1 }, - { 0x2aa6, 0x2aa7 }, - { 0x2aa7, 0x2aa6 }, - { 0x2aa8, 0x2aa9 }, - { 0x2aa9, 0x2aa8 }, - { 0x2aaa, 0x2aab }, - { 0x2aab, 0x2aaa }, - { 0x2aac, 0x2aad }, - { 0x2aad, 0x2aac }, - { 0x2aaf, 0x2ab0 }, - { 0x2ab0, 0x2aaf }, - { 0x2ab3, 0x2ab4 }, - { 0x2ab4, 0x2ab3 }, - { 0x2abb, 0x2abc }, - { 0x2abc, 0x2abb }, - { 0x2abd, 0x2abe }, - { 0x2abe, 0x2abd }, - { 0x2abf, 0x2ac0 }, - { 0x2ac0, 0x2abf }, - { 0x2ac1, 0x2ac2 }, - { 0x2ac2, 0x2ac1 }, - { 0x2ac3, 0x2ac4 }, - { 0x2ac4, 0x2ac3 }, - { 0x2ac5, 0x2ac6 }, - { 0x2ac6, 0x2ac5 }, - { 0x2acd, 0x2ace }, - { 0x2ace, 0x2acd }, - { 0x2acf, 0x2ad0 }, - { 0x2ad0, 0x2acf }, - { 0x2ad1, 0x2ad2 }, - { 0x2ad2, 0x2ad1 }, - { 0x2ad3, 0x2ad4 }, - { 0x2ad4, 0x2ad3 }, - { 0x2ad5, 0x2ad6 }, - { 0x2ad6, 0x2ad5 }, - { 0x2ade, 0x22a6 }, - { 0x2ae3, 0x22a9 }, - { 0x2ae4, 0x22a8 }, - { 0x2ae5, 0x22ab }, - { 0x2aec, 0x2aed }, - { 0x2aed, 0x2aec }, - { 0x2af7, 0x2af8 }, - { 0x2af8, 0x2af7 }, - { 0x2af9, 0x2afa }, - { 0x2afa, 0x2af9 }, - { 0x2e02, 0x2e03 }, - { 0x2e03, 0x2e02 }, - { 0x2e04, 0x2e05 }, - { 0x2e05, 0x2e04 }, - { 0x2e09, 0x2e0a }, - { 0x2e0a, 0x2e09 }, - { 0x2e0c, 0x2e0d }, - { 0x2e0d, 0x2e0c }, - { 0x2e1c, 0x2e1d }, - { 0x2e1d, 0x2e1c }, - { 0x3008, 0x3009 }, - { 0x3009, 0x3008 }, - { 0x300a, 0x300b }, - { 0x300b, 0x300a }, - { 0x300c, 0x300d }, - { 0x300d, 0x300c }, - { 0x300e, 0x300f }, - { 0x300f, 0x300e }, - { 0x3010, 0x3011 }, - { 0x3011, 0x3010 }, - { 0x3014, 0x3015 }, - { 0x3015, 0x3014 }, - { 0x3016, 0x3017 }, - { 0x3017, 0x3016 }, - { 0x3018, 0x3019 }, - { 0x3019, 0x3018 }, - { 0x301a, 0x301b }, - { 0x301b, 0x301a }, - { 0xff08, 0xff09 }, - { 0xff09, 0xff08 }, - { 0xff1c, 0xff1e }, - { 0xff1e, 0xff1c }, - { 0xff3b, 0xff3d }, - { 0xff3d, 0xff3b }, - { 0xff5b, 0xff5d }, - { 0xff5d, 0xff5b }, - { 0xff5f, 0xff60 }, - { 0xff60, 0xff5f }, - { 0xff62, 0xff63 }, - { 0xff63, 0xff62 } -}; - #endif /* CHARTABLES_H */ diff --git a/glib/guniprop.c b/glib/guniprop.c index 6c88a27..02cd0e2 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;