summaryrefslogtreecommitdiff
path: root/av.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2016-08-17 09:59:06 +0100
committerDavid Mitchell <davem@iabyn.com>2016-08-17 13:38:56 +0100
commit93a3e97518c1f1e5d6916e1550a36f0d39d520e6 (patch)
tree278d63c94a5514c3140f9dd796552240d1206204 /av.c
parent1d7e6444bd515142acf34ef230b50f9d80ab9017 (diff)
downloadperl-93a3e97518c1f1e5d6916e1550a36f0d39d520e6.tar.gz
av_fetch(): optimise the negative index branch.
For a negative index one conditional is redundant, since after determining that key < 0 and recomputing key as (AvFILLp(av) - key), key can't be > AvFILLp(av).
Diffstat (limited to 'av.c')
-rw-r--r--av.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/av.c b/av.c
index a48702bb7d..8967da5703 100644
--- a/av.c
+++ b/av.c
@@ -272,9 +272,11 @@ Perl_av_fetch(pTHX_ AV *av, SSize_t key, I32 lval)
key += AvFILLp(av) + 1;
if (key < 0)
return NULL;
+ assert(key <= AvFILLp(av));
+ if (!AvARRAY(av)[key])
+ goto emptyness;
}
-
- if (key > AvFILLp(av) || !AvARRAY(av)[key]) {
+ else if (key > AvFILLp(av) || !AvARRAY(av)[key]) {
emptyness:
return lval ? av_store(av,key,newSV(0)) : NULL;
}