diff options
author | Karl Williamson <khw@cpan.org> | 2015-03-10 13:16:23 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2015-03-12 22:27:24 -0600 |
commit | 273e254d1663b9223905e4b5c3b6546671ba365e (patch) | |
tree | fa885f34be93dec56fbbbd41e3daf03fb09f30d0 /lib | |
parent | e6965c14693b6cad1c65f3a588597285a0e525a2 (diff) | |
download | perl-273e254d1663b9223905e4b5c3b6546671ba365e.tar.gz |
Optimize out unicode_to_native(), native_to_unicode()
These just return their argument on ASCII platforms, so can get rid of
the function call overhead there.
Thanks to Zefram and Matthew Horsfall for their help in this.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utf8.pm | 10 | ||||
-rw-r--r-- | lib/utf8.t | 17 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/utf8.pm b/lib/utf8.pm index 4980c7c7c3..ed23b61386 100644 --- a/lib/utf8.pm +++ b/lib/utf8.pm @@ -2,7 +2,7 @@ package utf8; $utf8::hint_bits = 0x00800000; -our $VERSION = '1.14'; +our $VERSION = '1.15'; sub import { $^H |= $utf8::hint_bits; @@ -186,6 +186,7 @@ L<Encode>. =item * C<$unicode = utf8::native_to_unicode($code_point)> +(Since Perl v5.8.0) This takes an unsigned integer (which represents the ordinal number of a character (or a code point) on the platform the program is being run on) and returns its Unicode equivalent value. Since ASCII platforms natively use the @@ -195,8 +196,12 @@ platforms it converts from EBCIDC to Unicode. A meaningless value will currently be returned if the input is not an unsigned integer. +Since Perl v5.22.0, calls to this function are optimized out on ASCII +platforms, so there is no performance hit in using it there. + =item * C<$native = utf8::unicode_to_native($code_point)> +(Since Perl v5.8.0) This is the inverse of C<utf8::native_to_unicode()>, converting the other direction. Again, on ASCII platforms, this returns its input, but on EBCDIC platforms it will find the native platform code point, given any Unicode one. @@ -204,6 +209,9 @@ platforms it will find the native platform code point, given any Unicode one. A meaningless value will currently be returned if the input is not an unsigned integer. +Since Perl v5.22.0, calls to this function are optimized out on ASCII +platforms, so there is no performance hit in using it there. + =item * C<$flag = utf8::is_utf8($string)> (Since Perl 5.8.1) Test whether I<$string> is marked internally as encoded in diff --git a/lib/utf8.t b/lib/utf8.t index 8578444fb8..bf722f3797 100644 --- a/lib/utf8.t +++ b/lib/utf8.t @@ -481,7 +481,7 @@ SKIP: { use strict; my $s = "hlagh"; my $r = \$s; - %s($r); + my $dummy = %s($r); $$r; ], $func; my $ret = eval $code or my $error = $@; @@ -603,6 +603,21 @@ for my $pos (0..5) { is($s, "A$utf8_bytes","(pos $pos) str after U; utf8::encode"); } +SKIP: { + skip("Test only valid on ASCII platform", 1) unless $::IS_ASCII; + require Config; + skip("Test needs a B module, which is lacking in this Perl", 1) + if $Config::Config{'extensions'} !~ /\bB\b/; + + my $out = runperl ( switches => ["-XMO=Concise"], + prog => 'utf8::unicode_to_native(0x41); + utf8::native_to_unicode(0x42)', + stderr => 1 ); + unlike($out, qr/entersub/, + "utf8::unicode_to_native() and native_to_unicode() optimized out"); +} + + # [perl #119043] utf8::upgrade should not croak on read-only COWs for(__PACKAGE__) { eval { utf8::upgrade($_) }; |