Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.95k stars 554 forks source link

bytes_from_utf8_loc: Move declarations, rename variable #22639

Closed khwilliamson closed 19 hours ago

khwilliamson commented 2 weeks ago

Now that we have c99, we can declare close to first use. s0 seems to be the more common name for a variable that preserves the position a string 's' had on input. This also adds a const to make sure the function doesn't change s0. bytes_from_utf8: Copy initial invariants as-is

 The paradigm used in this commit is in place in several other places in
 core.  When dealing with UTF-8, it may well be that the first part of a
 string contains only characters that are the same when encoded as UTF-8
 as when not.  There is a function that finds the first position in a
 string not like that.  It works on a whole word at a time instead of
 per-byte, effectively speeding things up by a factor of 8.

 In this case, calling that function tells us that we can use memcpy() to
 do the initial part of our task, before having to switch to looking at
 individual bytes.