Skip to content

Commit 3a25432

Browse files
hvdskhwilliamson
authored andcommitted
op.c: hoist first-pass logic out of loop in pmtrans()
Mainly to avoid gcc warnings that found the logic too complex to follow.
1 parent 513aa6a commit 3a25432

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

op.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7013,37 +7013,34 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
70137013

70147014
t_invlist = _new_invlist(1);
70157015

7016+
/* Initialize to a single range */
7017+
t_invlist = _add_range_to_invlist(t_invlist, 0, UV_MAX);
7018+
7019+
/* For the first pass, the lhs is partitioned such that the
7020+
* number of UTF-8 bytes required to represent a code point in each
7021+
* partition is the same as the number for any other code point in
7022+
* that partion. We copy the pre-compiled partion. */
7023+
len = C_ARRAY_LENGTH(PL_partition_by_byte_length);
7024+
invlist_extend(t_invlist, len);
7025+
t_array = invlist_array(t_invlist);
7026+
Copy(PL_partition_by_byte_length, t_array, len, UV);
7027+
invlist_set_len(t_invlist, len, *(get_invlist_offset_addr(t_invlist)));
7028+
Newx(r_map, len + 1, UV);
7029+
70167030
/* Parse the (potentially adjusted) input, creating the inversion map.
70177031
* This is done in two passes. The first pass is to determine if the
70187032
* transliteration can be done in place. The inversion map it creates
70197033
* could be used, but generally would be larger and slower to run than the
70207034
* output of the second pass, which starts with a more compact table and
70217035
* allows more ranges to be merged */
70227036
for (pass2 = 0; pass2 < 2; pass2++) {
7023-
7024-
/* Initialize to a single range */
7025-
t_invlist = _add_range_to_invlist(t_invlist, 0, UV_MAX);
7026-
7027-
/* In the second pass, we just have the single range */
7028-
70297037
if (pass2) {
7030-
len = 1;
7031-
t_array = invlist_array(t_invlist);
7032-
}
7033-
else {
7038+
/* Initialize to a single range */
7039+
t_invlist = _add_range_to_invlist(t_invlist, 0, UV_MAX);
70347040

7035-
/* But in the first pass, the lhs is partitioned such that the
7036-
* number of UTF-8 bytes required to represent a code point in each
7037-
* partition is the same as the number for any other code point in
7038-
* that partion. We copy the pre-compiled partion. */
7039-
len = C_ARRAY_LENGTH(PL_partition_by_byte_length);
7040-
invlist_extend(t_invlist, len);
7041+
/* In the second pass, we just have the single range */
7042+
len = 1;
70417043
t_array = invlist_array(t_invlist);
7042-
Copy(PL_partition_by_byte_length, t_array, len, UV);
7043-
invlist_set_len(t_invlist,
7044-
len,
7045-
*(get_invlist_offset_addr(t_invlist)));
7046-
Newx(r_map, len + 1, UV);
70477044
}
70487045

70497046
/* And the mapping of each of the ranges is initialized. Initially,

0 commit comments

Comments
 (0)