summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorHugo van der Sanden <hv@crypt.org>2020-02-01 12:20:42 +0000
committerKarl Williamson <khw@cpan.org>2020-02-01 09:00:26 -0700
commit3a25432294a38b1c9c70d459c84132b7d76f245a (patch)
tree6fb960e760f346d8b9d2576f718b08ad14e5646c /op.c
parent513aa6a56d4d5d1b21b81a4a9cf3339eae527a1b (diff)
downloadperl-3a25432294a38b1c9c70d459c84132b7d76f245a.tar.gz
op.c: hoist first-pass logic out of loop in pmtrans()
Mainly to avoid gcc warnings that found the logic too complex to follow.
Diffstat (limited to 'op.c')
-rw-r--r--op.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/op.c b/op.c
index f5f61c72c9..6e2897b1e0 100644
--- a/op.c
+++ b/op.c
@@ -7013,6 +7013,20 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
t_invlist = _new_invlist(1);
+ /* Initialize to a single range */
+ t_invlist = _add_range_to_invlist(t_invlist, 0, UV_MAX);
+
+ /* For the first pass, the lhs is partitioned such that the
+ * number of UTF-8 bytes required to represent a code point in each
+ * partition is the same as the number for any other code point in
+ * that partion. We copy the pre-compiled partion. */
+ len = C_ARRAY_LENGTH(PL_partition_by_byte_length);
+ invlist_extend(t_invlist, len);
+ t_array = invlist_array(t_invlist);
+ Copy(PL_partition_by_byte_length, t_array, len, UV);
+ invlist_set_len(t_invlist, len, *(get_invlist_offset_addr(t_invlist)));
+ Newx(r_map, len + 1, UV);
+
/* Parse the (potentially adjusted) input, creating the inversion map.
* This is done in two passes. The first pass is to determine if the
* transliteration can be done in place. The inversion map it creates
@@ -7020,30 +7034,13 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
* output of the second pass, which starts with a more compact table and
* allows more ranges to be merged */
for (pass2 = 0; pass2 < 2; pass2++) {
-
- /* Initialize to a single range */
- t_invlist = _add_range_to_invlist(t_invlist, 0, UV_MAX);
-
- /* In the second pass, we just have the single range */
-
if (pass2) {
- len = 1;
- t_array = invlist_array(t_invlist);
- }
- else {
+ /* Initialize to a single range */
+ t_invlist = _add_range_to_invlist(t_invlist, 0, UV_MAX);
- /* But in the first pass, the lhs is partitioned such that the
- * number of UTF-8 bytes required to represent a code point in each
- * partition is the same as the number for any other code point in
- * that partion. We copy the pre-compiled partion. */
- len = C_ARRAY_LENGTH(PL_partition_by_byte_length);
- invlist_extend(t_invlist, len);
+ /* In the second pass, we just have the single range */
+ len = 1;
t_array = invlist_array(t_invlist);
- Copy(PL_partition_by_byte_length, t_array, len, UV);
- invlist_set_len(t_invlist,
- len,
- *(get_invlist_offset_addr(t_invlist)));
- Newx(r_map, len + 1, UV);
}
/* And the mapping of each of the ranges is initialized. Initially,