summaryrefslogtreecommitdiff
path: root/lib/charnames.pm
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-12-01 15:40:13 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-12-01 15:40:13 +0000
commit4e2cda5de1463f636caa8d7626a38efc5bdd4d8d (patch)
tree367a72f37d2d7d1e00511c3e94fcff702a8af327 /lib/charnames.pm
parent248e172a5c70a92f68eb1fb746fb20e71358b43b (diff)
downloadperl-4e2cda5de1463f636caa8d7626a38efc5bdd4d8d.tar.gz
Add simple caches for ::viacode() and ::vianame().
p4raw-id: //depot/perl@13399
Diffstat (limited to 'lib/charnames.pm')
-rw-r--r--lib/charnames.pm14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/charnames.pm b/lib/charnames.pm
index 5554ae0368..ec200ec98d 100644
--- a/lib/charnames.pm
+++ b/lib/charnames.pm
@@ -123,6 +123,8 @@ sub import
}
}
+my %viacode;
+
sub viacode
{
if (@_ != 1) {
@@ -139,15 +141,19 @@ sub viacode
return;
}
+ return $viacode{$hex} if exists $viacode{$hex};
+
$txt = do "unicore/Name.pl" unless $txt;
if ($txt =~ m/^$hex\t\t(.+)/m) {
- return $1;
+ return $viacode{$hex} = $1;
} else {
return;
}
}
+my %vianame;
+
sub vianame
{
if (@_ != 1) {
@@ -157,10 +163,12 @@ sub vianame
my $arg = shift;
+ return $vianame{$arg} if exists $vianame{$arg};
+
$txt = do "unicore/Name.pl" unless $txt;
if ($txt =~ m/^([0-9A-F]+)\t\t($arg)/m) {
- return hex $1;
+ return $vianame{$arg} = hex $1;
} else {
return;
}
@@ -213,7 +221,7 @@ is ignored.
Note that C<\N{...}> is compile-time, it's a special form of string
constant used inside double-quoted strings: in other words, you cannot
-used variables inside the C<\N{...}>. If you want similar run-time
+use variables inside the C<\N{...}>. If you want similar run-time
functionality, use charnames::vianame().
=head1 CUSTOM TRANSLATORS