summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Leach <richardleach@users.noreply.github.com>2022-06-07 22:17:04 +0000
committerKarl Williamson <khw@cpan.org>2022-06-08 09:41:44 -0600
commit74279cb654174c8653f8e15198a6aa843636148e (patch)
treecd69ab896beaf66c5155be59fe932be400555960
parenteae3cc9643eecd5d8b27c8fb4a3dc3bfebaf57e3 (diff)
downloadperl-74279cb654174c8653f8e15198a6aa843636148e.tar.gz
Make use of av_push_simple in a few places.
Specifically, only where a new AV has just been created and it's therefore obvious that av_push_simple is safe to use. In many cases, nearby code does av_push to an existing array. It might well be the case that these are simple arrays and av_push_simple could be used instead. The necessary analysis has been left for the future.
-rw-r--r--mro_core.c12
-rw-r--r--perlio.c8
-rw-r--r--sv.c12
3 files changed, 17 insertions, 15 deletions
diff --git a/mro_core.c b/mro_core.c
index 42a11af035..235dacaec7 100644
--- a/mro_core.c
+++ b/mro_core.c
@@ -268,7 +268,7 @@ S_mro_get_linear_isa_dfs(pTHX_ HV *stash, U32 level)
/* We use this later in this function, but don't need a reference to it
beyond the end of this function, so reference count is fine. */
our_name = newSVhek(stashhek);
- av_push(retval, our_name); /* add ourselves at the top */
+ av_push_simple(retval, our_name); /* add ourselves at the top */
/* fetch our @ISA */
gvp = (GV**)hv_fetchs(stash, "ISA", FALSE);
@@ -326,7 +326,7 @@ S_mro_get_linear_isa_dfs(pTHX_ HV *stash, U32 level)
HeVAL(he) = &PL_sv_undef;
sv_sethek(val, key);
- av_push(retval, val);
+ av_push_simple(retval, val);
}
}
} else {
@@ -358,7 +358,7 @@ S_mro_get_linear_isa_dfs(pTHX_ HV *stash, U32 level)
as if we'd copied it from what theirs should be. */
stored = MUTABLE_HV(newSV_type_mortal(SVt_PVHV));
(void) hv_stores(stored, "UNIVERSAL", &PL_sv_undef);
- av_push(retval,
+ av_push_simple(retval,
newSVhek(HeKEY_hek(hv_store_ent(stored, sv,
&PL_sv_undef, 0))));
}
@@ -846,7 +846,7 @@ Perl_mro_package_moved(pTHX_ HV * const stash, HV * const oldstash,
GvNAMEUTF8(gv) ? SV_CATUTF8 : SV_CATBYTES
);
}
- av_push((AV *)namesv, aname);
+ av_push_simple((AV *)namesv, aname);
}
}
@@ -1186,7 +1186,7 @@ S_mro_gather_and_rename(pTHX_ HV * const stashes, HV * const seen_stashes,
? SV_CATUTF8 : SV_CATBYTES
);
}
- av_push((AV *)subname, aname);
+ av_push_simple((AV *)subname, aname);
}
}
else {
@@ -1269,7 +1269,7 @@ S_mro_gather_and_rename(pTHX_ HV * const stashes, HV * const seen_stashes,
? SV_CATUTF8 : SV_CATBYTES
);
}
- av_push((AV *)subname, aname);
+ av_push_simple((AV *)subname, aname);
}
}
else {
diff --git a/perlio.c b/perlio.c
index f2803a4025..e3223d6d42 100644
--- a/perlio.c
+++ b/perlio.c
@@ -690,9 +690,9 @@ PerlIO_get_layers(pTHX_ PerlIO *f)
newSVpv(l->tab->name, 0) : &PL_sv_undef;
SV * const arg = l->tab && l->tab->Getarg ?
(*l->tab->Getarg)(aTHX_ &l, 0, 0) : &PL_sv_undef;
- av_push(av, name);
- av_push(av, arg);
- av_push(av, newSViv((IV)l->flags));
+ av_push_simple(av, name);
+ av_push_simple(av, arg);
+ av_push_simple(av, newSViv((IV)l->flags));
l = l->next;
}
}
@@ -818,7 +818,7 @@ XS(XS_io_MODIFY_SCALAR_ATTRIBUTES)
const char * const name = SvPV_const(ST(i), len);
SV * const layer = PerlIO_find_layer(aTHX_ name, len, 1);
if (layer) {
- av_push(av, SvREFCNT_inc_simple_NN(layer));
+ av_push_simple(av, SvREFCNT_inc_simple_NN(layer));
}
else {
ST(count) = ST(i);
diff --git a/sv.c b/sv.c
index 0d16d75c13..fb349c4956 100644
--- a/sv.c
+++ b/sv.c
@@ -3775,11 +3775,13 @@ S_glob_assign_glob(pTHX_ SV *const dsv, SV *const ssv, const int dtype)
SV * const sref = (SV *)GvAV((const GV *)dsv);
if (SvSMAGICAL(sref) && (mg = mg_find(sref, PERL_MAGIC_isa))) {
if (SvTYPE(mg->mg_obj) != SVt_PVAV) {
- AV * const ary = newAV();
- av_push(ary, mg->mg_obj); /* takes the refcount */
+ AV * const ary = newAV_alloc_x(2);
+ av_push_simple(ary, mg->mg_obj); /* takes the refcount */
+ av_push_simple(ary, SvREFCNT_inc_simple_NN(dsv));
mg->mg_obj = (SV *)ary;
+ } else {
+ av_push((AV *)mg->mg_obj, SvREFCNT_inc_simple_NN(dsv));
}
- av_push((AV *)mg->mg_obj, SvREFCNT_inc_simple_NN(dsv));
}
else sv_magic(sref, dsv, PERL_MAGIC_isa, NULL, 0);
}
@@ -3958,8 +3960,8 @@ Perl_gv_setref(pTHX_ SV *const dsv, SV *const ssv)
: NULL;
if (SvSMAGICAL(sref) && (mg = mg_find(sref, PERL_MAGIC_isa))) {
if (SvTYPE(mg->mg_obj) != SVt_PVAV) {
- AV * const ary = newAV();
- av_push(ary, mg->mg_obj); /* takes the refcount */
+ AV * const ary = newAV_alloc_xz(4);
+ av_push_simple(ary, mg->mg_obj); /* takes the refcount */
mg->mg_obj = (SV *)ary;
}
if (omg) {