Branch: refs/heads/blead
Home: https://github.com/Perl/perl5
Commit: 7ad0f4c08785d7e8889ad6a65bbe3eaef8a5761c
https://github.com/Perl/perl5/commit/7ad0f4c08785d7e8889ad6a65bbe3eaef8a5761c
Author: Karl Williamson <[email protected]>
Date: 2026-07-16 (Thu, 16 Jul 2026)
Changed paths:
M utf8.c
Log Message:
-----------
utf8_length(): Assert input positioned properly
I rewrote this function in 2019 via 71d63d0dc to do calculations per-word
versus by character for long enough strings, thus saving significant
amounts of execution time. FYI, at the bottom is a copy of some of the
data presented in that commit message.
The function traditionally did just a bit of syntax error checking of
the parsed string. I chose to not add any, since the goal was speed,
but also chose to not take any away, so that it would behave the same as
always. That caused a tiny bit of slowdown than if checking were
eliminated.
This commit adds a new check at the beginning of the function
in the form of an assert (active only in DEBUG builds) that the input
string is either empty or positioned at the beginning of a character.
This should have been a no-brainer, adding essentially no extra cycles
and verifying an important sanity criterium
(The PERL_ARGS_ASSERT_UTF8_LENGTH macro already asserts that s0 is not
greater than e)
------------------------- Data from 2019 commit
Very long strings run an order of magnitude fewer instructions than
blead. Here are worst case scenarios (7 bytes after word boundary).
The values are in terms of percent, with blead (at the time) always
set to 100. Numbers above 100 are good; below bad
string length 10000000 characters; 1 bytes per character
blead patch
------ -------
Ir 100.00 814.53
Dr 100.00 1069.58
Dw 100.00 3296.55
COND 100.00 1575.83
IND 100.00 100.00
string length 5000000 characters; 2 bytes per character
blead patch
------ -------
Ir 100.00 408.86
Dr 100.00 536.32
Dw 100.00 1698.31
COND 100.00 788.72
IND 100.00 100.00
string length 3333333 characters; 3 bytes per character
blead patch
------ -------
Ir 100.00 273.64
Dr 100.00 358.56
Dw 100.00 1165.55
COND 100.00 526.35
IND 100.00 100.00
string length 2500000 characters; 4 bytes per character
blead patch
------ -------
Ir 100.00 206.03
Dr 100.00 269.68
Dw 100.00 899.17
COND 100.00 395.17
IND 100.00 100.00
To unsubscribe from these emails, change your notification settings at
https://github.com/Perl/perl5/settings/notifications