This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
is_utf8_string(): Avoid a redundant conditional
authorKarl Williamson <khw@cpan.org>
Fri, 8 Dec 2023 15:49:58 +0000 (08:49 -0700)
committerKarl Williamson <khw@cpan.org>
Mon, 11 Dec 2023 03:43:26 +0000 (20:43 -0700)
commit12c770f1a7bb73ceacba88ea3d6094c1adc4d27d
tree51c73e7cdf7a1943d8a07a44387c26c0de9ff9e8
parent5eced48190355809e3c6b5d2c8de4c8c95ec0db5
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.
inline.h