@@ -9538,13 +9538,13 @@ S_compute_collxfrm_coefficients(pTHX)
95389538 PL_strxfrm_NUL_replacement = '\0' ;
95399539 PL_strxfrm_max_cp = 0 ;
95409540
9541- /* mem_collxfrm_() is used get the transformation (though here we are
9542- * interested only in its length). It is used because it has the
9543- * intelligence to handle all cases, but to work, it needs some values of
9544- * 'm' and 'b' to get it started. For the purposes of this calculation we
9545- * use a very conservative estimate of 'm' and 'b'. This assumes a weight
9546- * can be multiple bytes, enough to hold any UV on the platform, and there
9547- * are 5 levels, 4 weight bytes, and a trailing NUL. */
9541+ /* mem_collxfrm_() is used recursively to get the transformation (though
9542+ * here we are interested only in its length). It is used because it has
9543+ * the intelligence to handle all cases, but to work, it needs some values
9544+ * of 'm' and 'b' to get it started. For the purposes of this calculation
9545+ * we use a very conservative estimate of 'm' and 'b'. This assumes a
9546+ * weight can be multiple bytes, enough to hold any UV on the platform, and
9547+ * there are 5 levels, 4 weight bytes, and a trailing NUL. */
95489548 PL_collxfrm_base = 5 ;
95499549 PL_collxfrm_mult = 5 * sizeof (UV );
95509550
@@ -9588,37 +9588,36 @@ S_compute_collxfrm_coefficients(pTHX)
95889588 return false;
95899589 }
95909590
9591- SSize_t base ; /* Temporary */
9591+ SSize_t base ; /* Temporary */
95929592
9593- /* We have both: m * strlen(longer) + b = x_len_longer
9594- * m * strlen(shorter) + b = x_len_shorter;
9595- * subtracting yields:
9596- * m * (strlen(longer) - strlen(shorter))
9597- * = x_len_longer - x_len_shorter
9598- * But we have set things up so that 'shorter' is 1 byte smaller than
9599- * 'longer'. Hence:
9600- * m = x_len_longer - x_len_shorter
9601- *
9602- * But if something went wrong, make sure the multiplier is at least 1.
9603- */
9604- if (x_len_longer > x_len_shorter ) {
9605- PL_collxfrm_mult = (STRLEN ) x_len_longer - x_len_shorter ;
9606- }
9607- else {
9608- PL_collxfrm_mult = 1 ;
9609- }
9593+ /* We have both: m * strlen(longer) + b = x_len_longer
9594+ * m * strlen(shorter) + b = x_len_shorter;
9595+ * subtracting yields:
9596+ * m * (strlen(longer) - strlen(shorter))
9597+ * = x_len_longer - x_len_shorter
9598+ * But we have set things up so that 'shorter' is 1 byte smaller than
9599+ * 'longer'. Hence:
9600+ * m = x_len_longer - x_len_shorter
9601+ *
9602+ * But if something went wrong, make sure the multiplier is at least 1.
9603+ */
9604+ if (x_len_longer > x_len_shorter ) {
9605+ PL_collxfrm_mult = (STRLEN ) x_len_longer - x_len_shorter ;
9606+ }
9607+ else {
9608+ PL_collxfrm_mult = 1 ;
9609+ }
96109610
9611- /* mx + b = len
9612- * so: b = len - mx
9613- * but in case something has gone wrong, make sure it is non-negative
9614- * */
9615- base = x_len_longer - PL_collxfrm_mult * (sizeof (longer ) - 1 );
9616- if (base < 0 ) {
9617- base = 0 ;
9618- }
9611+ /* mx + b = len
9612+ * so: b = len - mx
9613+ * but in case something has gone wrong, make sure it is non-negative */
9614+ base = x_len_longer - PL_collxfrm_mult * (sizeof (longer ) - 1 );
9615+ if (base < 0 ) {
9616+ base = 0 ;
9617+ }
96199618
9620- /* Add 1 for the trailing NUL */
9621- PL_collxfrm_base = base + 1 ;
9619+ /* Add 1 for the trailing NUL */
9620+ PL_collxfrm_base = base + 1 ;
96229621
96239622 DEBUG_L (PerlIO_printf (Perl_debug_log ,
96249623 "?UTF-8 locale=%d; x_len_shorter=%zu, "
@@ -9765,7 +9764,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
97659764 /* Create a 1-char string of the current code point */
97669765 cur_source [0 ] = (char ) j ;
97679766
9768- /* Then transform it */
9767+ /* Then transform it using a recursive call */
97699768 x = mem_collxfrm_ (cur_source , trial_len , & x_len ,
97709769 0 /* The string is not in UTF-8 */ );
97719770
@@ -9925,7 +9924,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
99259924 /* Create a 1-char string of the current code point */
99269925 cur_source [0 ] = (char ) j ;
99279926
9928- /* Then transform it */
9927+ /* Then transform it (recursively) */
99299928 x = mem_collxfrm_ (cur_source , 1 , & x_len , FALSE);
99309929
99319930 /* If something went wrong (which it shouldn't), just
@@ -10221,7 +10220,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
1022110220 PL_collxfrm_mult = new_m ;
1022210221 PL_collxfrm_base = 1 ; /* +1 For trailing NUL */
1022310222 computed_guess = PL_collxfrm_base
10224- + (PL_collxfrm_mult * length_in_chars );
10223+ + (PL_collxfrm_mult * length_in_chars );
1022510224 if (computed_guess < needed ) {
1022610225 PL_collxfrm_base += needed - computed_guess ;
1022710226 }
0 commit comments