Commit 6c6e8539 authored by Behdad Esfahbod's avatar Behdad Esfahbod Committed by Behdad Esfahbod

Decrease the amount of non-shared data. #169491, Benoît Dejean, Behnam

2005-11-27  Behdad Esfahbod  <behdad@gnome.org>

        Decrease the amount of non-shared data.
        #169491, Benoît Dejean, Behnam Esfahbod.

        * gucharmap/gen-guch-unicode-tables.pl: Generate index-tables instead
        of pointer-tables, for Unihan table, and names table.

        * gucharmap/gucharmap-unicode-info.c: Update to follow.

        * gucharmap/unicode-names.h, gucharmap/unicode-unihan.h: Regenerated.
parent b953d94d
2005-11-27 Behdad Esfahbod <behdad@gnome.org>
Decrease the amount of non-shared data.
#169491, Benoît Dejean, Behnam Esfahbod.
* gucharmap/gen-guch-unicode-tables.pl: Generate index-tables instead
of pointer-tables, for Unihan table, and names table.
* gucharmap/gucharmap-unicode-info.c: Update to follow.
* gucharmap/unicode-names.h, gucharmap/unicode-unihan.h: Regenerated.
2005-11-28 Noah Levitt <nlevitt@columbia.edu>
* gucharmap/gucharmap-window.c: Fix ctrl+{pgdn,pgup}, which had
......
......@@ -93,28 +93,72 @@ sub process_unicode_data_txt ($)
print $out "#include <glib/gunicode.h>\n\n";
my @unicode_pairs;
my %names;
while (my $line = <$unicodedata>)
{
chomp $line;
$line =~ /^([^;]+);([^;]+)/ or die;
my $hex = $1;
my $name = $2;
$names{$name} = 1;
push @unicode_pairs, [$hex, $name];
}
print $out "static const char unicode_names_strings[] = \\\n";
my $offset = 0;
foreach my $name (sort keys %names) {
print $out " \"$name\\0\"\n";
$names{$name} = $offset;
$offset += length($name) + 1;
}
undef $offset;
print $out ";\n";
print $out "typedef struct _UnicodeName UnicodeName;\n\n";
print $out "static const struct _UnicodeName\n";
print $out "{\n";
print $out " gunichar index;\n";
print $out " const gchar *name;\n";
print $out " guint32 name_offset;\n";
print $out "} \n";
print $out "unicode_names[] =\n";
print $out "{\n";
while (my $line = <$unicodedata>)
{
chomp $line;
$line =~ /^([^;]+);([^;]+)/ or die;
my $first_line = 1;
my $hex = $1;
my $name = $2;
foreach my $pair (@unicode_pairs) {
if (!$first_line) {
print $out ",\n";
} else {
$first_line = 0;
}
print $out qq( { 0x$hex, "$name" },\n);
my ($hex, $name) = @{$pair};
my $offset = $names{$name};
print $out " {0x$hex, $offset}";
}
print $out "};\n\n";
print $out "\n};\n\n";
print $out <<EOT;
static inline const char * unicode_name_get_name(const UnicodeName *entry)
{
guint32 offset = entry->name_offset;
return unicode_names_strings + offset;
}
EOT
undef %names;
undef @unicode_pairs;
close ($unicodedata);
close ($out);
......@@ -251,19 +295,22 @@ sub process_unihan_zip ($)
print $out "static const struct _Unihan\n";
print $out "{\n";
print $out " gunichar index;\n";
print $out " const gchar *kDefinition;\n";
print $out " const gchar *kCantonese;\n";
print $out " const gchar *kMandarin;\n";
print $out " const gchar *kTang;\n";
print $out " const gchar *kKorean;\n";
print $out " const gchar *kJapeneseKun;\n";
print $out " const gchar *kJapaneseOn;\n";
print $out " gint32 kDefinition;\n";
print $out " gint32 kCantonese;\n";
print $out " gint32 kMandarin;\n";
print $out " gint32 kTang;\n";
print $out " gint32 kKorean;\n";
print $out " gint32 kJapaneseKun;\n";
print $out " gint32 kJapaneseOn;\n";
print $out "} \n";
print $out "unihan[] =\n";
print $out "{\n";
my @strings;
my $offset = 0;
my $wc = 0;
my ($kDefinition, $kCantonese, $kMandarin, $kTang, $kKorean, $kJapeneseKun, $kJapaneseOn);
my ($kDefinition, $kCantonese, $kMandarin, $kTang, $kKorean, $kJapaneseKun, $kJapaneseOn);
my $i = 0;
while (my $line = <$unihan>)
......@@ -277,23 +324,22 @@ sub process_unihan_zip ($)
my $value = $3;
$value =~ s/\\/\\\\/g;
$value =~ s/\"/\\"/g;
$value = qq("$value");
if ($new_wc != $wc)
{
if (defined $kDefinition or defined $kCantonese or defined $kMandarin
or defined $kTang or defined $kKorean or defined $kJapeneseKun
or defined $kTang or defined $kKorean or defined $kJapaneseKun
or defined $kJapaneseOn)
{
printf $out (" { 0x%04X, \%s, \%s, \%s, \%s, \%s, \%s, \%s },\n",
printf $out (" { 0x%04X, \%d, \%d, \%d, \%d, \%d, \%d, \%d },\n",
$wc,
$kDefinition || "NULL",
$kCantonese || "NULL",
$kMandarin || "NULL",
$kTang || "NULL",
$kKorean || "NULL",
$kJapeneseKun || "NULL",
$kJapaneseOn || "NULL");
(defined($kDefinition) ? $kDefinition : -1),
(defined($kCantonese) ? $kCantonese: -1),
(defined($kMandarin) ? $kMandarin : -1),
(defined($kTang) ? $kTang : -1),
(defined($kKorean) ? $kKorean : -1),
(defined($kJapaneseKun) ? $kJapaneseKun : -1),
(defined($kJapaneseOn) ? $kJapaneseOn : -1));
}
$wc = $new_wc;
......@@ -303,10 +349,21 @@ sub process_unihan_zip ($)
undef $kMandarin;
undef $kTang;
undef $kKorean;
undef $kJapeneseKun;
undef $kJapaneseKun;
undef $kJapaneseOn;
}
for my $f qw(kDefinition kCantonese kMandarin
kTang kKorean kJapaneseKun kJapaneseOn) {
if ($field eq $f) {
push @strings, $value;
my $last_offset = $offset;
$offset += length($value) + 1;
$value = $last_offset;
last;
}
}
if ($field eq "kDefinition") {
$kDefinition = $value;
......@@ -323,8 +380,8 @@ sub process_unihan_zip ($)
elsif ($field eq "kKorean") {
$kKorean = $value;
}
elsif ($field eq "kJapeneseKun") {
$kJapeneseKun = $value;
elsif ($field eq "kJapaneseKun") {
$kJapaneseKun = $value;
}
elsif ($field eq "kJapaneseOn") {
$kJapaneseOn = $value;
......@@ -337,6 +394,40 @@ sub process_unihan_zip ($)
print $out "};\n\n";
print $out "static const char unihan_strings[] = \\\n";
for my $s (@strings) {
print $out " \"$s\\0\"\n";
}
print $out ";\n\n";
print $out "static const Unihan *_get_unihan (gunichar uc)\n;";
for my $name qw(kDefinition kCantonese kMandarin
kTang kKorean kJapaneseKun kJapaneseOn) {
print $out <<EOT;
static inline const char * unihan_get_$name (const Unihan *uh)
{
gint32 offset = uh->$name;
if (offset == -1)
return NULL;
return unihan_strings + offset;
}
G_CONST_RETURN gchar *
gucharmap_get_unicode_$name (gunichar uc)
{
const Unihan *uh = _get_unihan (uc);
if (uh == NULL)
return NULL;
else
return unihan_get_$name (uh);
}
EOT
}
close ($unihan);
close ($out);
......
......@@ -216,7 +216,7 @@ gucharmap_get_unicode_data_name (gunichar uc)
{
gint min = 0;
gint mid;
gint max = sizeof (unicode_names) / sizeof (UnicodeName) - 1;
gint max = G_N_ELEMENTS(unicode_names) - 1;
if (uc < unicode_names[0].index || uc > unicode_names[max].index)
return "";
......@@ -229,7 +229,7 @@ gucharmap_get_unicode_data_name (gunichar uc)
else if (uc < unicode_names[mid].index)
max = mid - 1;
else
return unicode_names[mid].name;
return unicode_name_get_name(&unicode_names[mid]);
}
return NULL;
......@@ -258,7 +258,8 @@ _get_unihan (gunichar uc)
static const Unihan *most_recent_result;
gint min = 0;
gint mid;
gint max = sizeof (unihan) / sizeof (Unihan) - 1;
gint max = G_N_ELEMENTS(unihan) - 1;
if (uc < unihan[0].index || uc > unihan[max].index)
return NULL;
......@@ -286,76 +287,6 @@ _get_unihan (gunichar uc)
return NULL;
}
G_CONST_RETURN gchar *
gucharmap_get_unicode_kDefinition (gunichar uc)
{
const Unihan *uh = _get_unihan (uc);
if (uh == NULL)
return NULL;
else
return uh->kDefinition;
}
G_CONST_RETURN gchar *
gucharmap_get_unicode_kCantonese (gunichar uc)
{
const Unihan *uh = _get_unihan (uc);
if (uh == NULL)
return NULL;
else
return uh->kCantonese;
}
G_CONST_RETURN gchar *
gucharmap_get_unicode_kMandarin (gunichar uc)
{
const Unihan *uh = _get_unihan (uc);
if (uh == NULL)
return NULL;
else
return uh->kMandarin;
}
G_CONST_RETURN gchar *
gucharmap_get_unicode_kTang (gunichar uc)
{
const Unihan *uh = _get_unihan (uc);
if (uh == NULL)
return NULL;
else
return uh->kTang;
}
G_CONST_RETURN gchar *
gucharmap_get_unicode_kKorean (gunichar uc)
{
const Unihan *uh = _get_unihan (uc);
if (uh == NULL)
return NULL;
else
return uh->kKorean;
}
G_CONST_RETURN gchar *
gucharmap_get_unicode_kJapaneseKun (gunichar uc)
{
const Unihan *uh = _get_unihan (uc);
if (uh == NULL)
return NULL;
else
return uh->kJapeneseKun;
}
G_CONST_RETURN gchar *
gucharmap_get_unicode_kJapaneseOn (gunichar uc)
{
const Unihan *uh = _get_unihan (uc);
if (uh == NULL)
return NULL;
else
return uh->kJapaneseOn;
}
#else /* #if ENABLE_UNIHAN */
gint
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment