develooper Front page | perl.perl5.changes | Postings from December 2023

[Perl/perl5] 12c770: is_utf8_string(): Avoid a redundant conditional

From:
Karl Williamson via perl5-changes
Date:
December 11, 2023 03:43
Subject:
[Perl/perl5] 12c770: is_utf8_string(): Avoid a redundant conditional
Message ID:
Perl/perl5/push/refs/heads/blead/5eced4-12c770@github.com
  Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: 12c770f1a7bb73ceacba88ea3d6094c1adc4d27d
      https://github.com/Perl/perl5/commit/12c770f1a7bb73ceacba88ea3d6094c1adc4d27d
  Author: Karl Williamson <khw@cpan.org>
  Date:   2023-12-10 (Sun, 10 Dec 2023)

  Changed paths:
    M inline.h

  Log Message:
  -----------
  is_utf8_string(): Avoid a redundant conditional

This is actually implemented by Perl_is_utf8_string_loclen_flags(), and
until this commit unconditionally tested if the input 'len' is 0, and
does a strlen() if so.  It then potentially calls one of three API
functions which each can handle an input 'len' of 0.  That means each of
them test for len being 0 and call strlen() if so.

So, that means this function tests for 'len' 0, then checks to see if
any of those functions apply, and if so, calls that one, which then
tests for 'len' 0, redundantly.

But this function doesn't actually need to know the len unless none of
those three functions apply, so moving the check to later means in all
cases we only test for 'len' being 0 once.





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About