@@ -9538,13 +9538,13 @@ S_compute_collxfrm_coefficients(pTHX)
9538
9538
PL_strxfrm_NUL_replacement = '\0' ;
9539
9539
PL_strxfrm_max_cp = 0 ;
9540
9540
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. */
9548
9548
PL_collxfrm_base = 5 ;
9549
9549
PL_collxfrm_mult = 5 * sizeof (UV );
9550
9550
@@ -9588,37 +9588,36 @@ S_compute_collxfrm_coefficients(pTHX)
9588
9588
return false;
9589
9589
}
9590
9590
9591
- SSize_t base ; /* Temporary */
9591
+ SSize_t base ; /* Temporary */
9592
9592
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
+ }
9610
9610
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
+ }
9619
9618
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 ;
9622
9621
9623
9622
DEBUG_L (PerlIO_printf (Perl_debug_log ,
9624
9623
"?UTF-8 locale=%d; x_len_shorter=%zu, "
@@ -9765,7 +9764,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
9765
9764
/* Create a 1-char string of the current code point */
9766
9765
cur_source [0 ] = (char ) j ;
9767
9766
9768
- /* Then transform it */
9767
+ /* Then transform it using a recursive call */
9769
9768
x = mem_collxfrm_ (cur_source , trial_len , & x_len ,
9770
9769
0 /* The string is not in UTF-8 */ );
9771
9770
@@ -9925,7 +9924,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
9925
9924
/* Create a 1-char string of the current code point */
9926
9925
cur_source [0 ] = (char ) j ;
9927
9926
9928
- /* Then transform it */
9927
+ /* Then transform it (recursively) */
9929
9928
x = mem_collxfrm_ (cur_source , 1 , & x_len , FALSE);
9930
9929
9931
9930
/* If something went wrong (which it shouldn't), just
@@ -10221,7 +10220,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
10221
10220
PL_collxfrm_mult = new_m ;
10222
10221
PL_collxfrm_base = 1 ; /* +1 For trailing NUL */
10223
10222
computed_guess = PL_collxfrm_base
10224
- + (PL_collxfrm_mult * length_in_chars );
10223
+ + (PL_collxfrm_mult * length_in_chars );
10225
10224
if (computed_guess < needed ) {
10226
10225
PL_collxfrm_base += needed - computed_guess ;
10227
10226
}
0 commit comments