summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Raspass <jraspass@gmail.com>2014-12-06 22:51:57 +0000
committerFather Chrysostomos <sprout@cpan.org>2014-12-06 19:42:32 -0800
commit15c41403d2d0c2e464b1c4bf8497d45d28917282 (patch)
tree20373fbf1e14fe9dc029f5aeb7b548b6d61780b4
parentb4db5868141d6a659beb640efc92eabae9cd71c0 (diff)
downloadperl-15c41403d2d0c2e464b1c4bf8497d45d28917282.tar.gz
Tweak sv_pos_b2u_flags check in pp_index
There's no need to run sv_pos_b2u_flags if the retval is one as one byte can only be one character, therefore change the test to "> 1". This makes index on unicode strings that match at 1 slightly faster.
-rw-r--r--pp.c2
-rw-r--r--t/op/index.t6
-rw-r--r--t/perf/benchmarks6
3 files changed, 12 insertions, 2 deletions
diff --git a/pp.c b/pp.c
index 49798e2d93..97ad595119 100644
--- a/pp.c
+++ b/pp.c
@@ -3343,7 +3343,7 @@ PP(pp_index)
retval = -1;
else {
retval = little_p - big_p;
- if (retval > 0 && big_utf8)
+ if (retval > 1 && big_utf8)
retval = sv_pos_b2u_flags(big, retval, SV_CONST_RETURN);
}
SvREFCNT_dec(temp);
diff --git a/t/op/index.t b/t/op/index.t
index fd5a98fc48..29a477146e 100644
--- a/t/op/index.t
+++ b/t/op/index.t
@@ -8,7 +8,7 @@ BEGIN {
}
use strict;
-plan( tests => 121 );
+plan( tests => 122 );
run_tests() unless caller;
@@ -253,3 +253,7 @@ is index('the main road', __PACKAGE__), 4,
'[perl #119169] __PACKAGE__ as 2nd argument';
} # end of sub run_tests
+
+utf8::upgrade my $substr = "\x{a3}a";
+
+is index($substr, 'a'), 1, 'index reply reflects characters not octets';
diff --git a/t/perf/benchmarks b/t/perf/benchmarks
index c137d0c9ec..52e2af9400 100644
--- a/t/perf/benchmarks
+++ b/t/perf/benchmarks
@@ -69,5 +69,11 @@
setup => 'my ($x, $y)',
code => '($x, $y) = (1, 2)',
},
+
+ 'expr::index::utf8_postion_1' => {
+ desc => 'index of a utf8 string, matching at position 1',
+ setup => 'utf8::upgrade my $x = "abc"',
+ code => 'index $x, "b"',
+ },
];