develooper Front page | perl.perl5.porters | Postings from March 2021

Re: Let's talk about trim() so more

Thread Previous
Tony Cook
March 31, 2021 23:40
Re: Let's talk about trim() so more
Message ID:
On Wed, Mar 31, 2021 at 11:19:22AM -0400, Dan Book wrote:
> Just a slight addendum to this and Ben's excellent detail of the situation:
> the "effectively in-place" form can be (and I believe may already be, in
> the PR) optimized as a built-in to an actual in-place operation even when
> you don't write it as one.

Simple cases could be, like:

  my $x;
  $x = trim($x);

More complex variants:

  my @x;
  my $i;
  $x[$i] = trim $x[$i]; # $i might be magical

can't really be optimized that way.

The existing PR does optimize on:

  $y = trim $x;

where $y and $x, however complex they are as expressions, turn out to
be the same SV, but the code doesn't try to eliminate any other
duplication. eg. if $x and $y are lexicals, two padsv ops are produced.


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About