This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert "av_create_and_push/unshift_one: faster create via newAV_alloc_xz"
authorKarl Williamson <khw@cpan.org>
Sat, 31 Jul 2021 23:32:51 +0000 (17:32 -0600)
committerKarl Williamson <khw@cpan.org>
Sat, 31 Jul 2021 23:38:34 +0000 (17:38 -0600)
This reverts commit 71ca71bc8b733c80f8f8099bb4673ee629da1353.

It does not compile with C++:

g++ -c -DPERL_CORE -D_REENTRANT -D_GNU_SOURCE -Wno-deprecated -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -ansi -O0 -ggdb3 -Wall -Werror=pointer-arith -Werror=vla -Wextra -Wwrite-strings av.c
av.c: In function ‘SV** Perl_av_create_and_unshift_one(PerlInterpreter*, AV**, SV*)’:
av.c:735:16: error: cannot convert ‘SV* const’ {aka ‘sv* const’} to ‘SV**’ {aka ‘sv**’} in return
  735 |         return val;
      |                ^~~

av.c

diff --git a/av.c b/av.c
index cfc47a4..d2f0e0d 100644 (file)
--- a/av.c
+++ b/av.c
@@ -638,11 +638,9 @@ Perl_av_create_and_push(pTHX_ AV **const avp, SV *const val)
 {
     PERL_ARGS_ASSERT_AV_CREATE_AND_PUSH;
 
-    if (!*avp) {
-        *avp = newAV_alloc_xz(4);
-        AvARRAY(*avp)[ ++AvFILLp(*avp) ] = val;
-    } else
-        av_push(*avp, val);
+    if (!*avp)
+        *avp = newAV();
+    av_push(*avp, val);
 }
 
 /*
@@ -729,14 +727,10 @@ Perl_av_create_and_unshift_one(pTHX_ AV **const avp, SV *const val)
 {
     PERL_ARGS_ASSERT_AV_CREATE_AND_UNSHIFT_ONE;
 
-    if (!*avp) {
-        *avp = newAV_alloc_xz(4);
-        AvARRAY(*avp)[ ++AvFILLp(*avp) ] = val;
-        return val;
-    } else {
-        av_unshift(*avp, 1);
-        return av_store(*avp, 0, val);
-    }
+    if (!*avp)
+        *avp = newAV();
+    av_unshift(*avp, 1);
+    return av_store(*avp, 0, val);
 }
 
 /*