Reguarding the update, I believe you're suggesting it would be more efficient to implement

$a.$b.$c.$d

as

concat_assign( concat_assign( concat_assign( copy($a), $b ), $c, ), $d )

rather than how it's actually implemented. However, I believe it's being implemented as the following, which is practically the same (ever so slightly better):

concat_assign( concat_assign( concat( $a, $b ), $c, ), $d )

I believe that's what's causing the "S" to appear in concat's flags.

$ perl -MO=Concise,-exec -e'$a.$b.$c.$d' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <#> gvsv[*a] s 4 <#> gvsv[*b] s 5 <2> concat[t3] sK/2 6 <#> gvsv[*c] s 7 <2> concat[t5] sKS/2 8 <#> gvsv[*d] s 9 <2> concat[t7] vKS/2 a <@> leave[1 ref] vKP/REFC -e syntax OK

But the problem with both of the approaches is that enlarging the string buffer requires copying it (at least on this Debian machine), so the "buk" and current version is usually more expensive (6 bytes rather than 3) than the naïve one I had posted.

A string buffer is only given 4 extra bytes when it's grown, which is pityful. (In comparison, arrays are given N+4 extra elements!) Aside from adding more padding, one could convert concat into an N-ary operator rather than a binary operator.

sub concat_list :lvalue { my $tot_len; $tot_len += length($_) for @_; my $buf = ''; # Allocate $tot_len bytes. $buf .= $_ for @_; $buf }

In reply to Re: Optimising concat (was Order of evaluation/interpolation of references) by ikegami
in thread Order of evaluation/interpolation of references by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.