Skip to content

Commit 3553294

Browse files
author
Markus Westerlind
committed
refactor: Clarify the single char merging
1 parent 90962bf commit 3553294

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

idna/src/make_uts46_mapping_table.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,17 @@ def mergeable_key(r):
123123
unicode_str = group[0][3]
124124
optimized_ranges.append((first, last, mapping, unicode_str))
125125

126+
def is_single_char_range(r):
127+
(first, last, _, _) = r
128+
return first == last
129+
126130
# We can reduce the size of the character range table and the index table to about 1/4
127131
# by merging runs of single character ranges and using character offsets from the start
128132
# of that range to retrieve the correct `Mapping` value
129133
def merge_single_char_ranges(ranges):
130134
current = []
131135
for r in ranges:
132-
mapping = r[2]
133-
134-
if not current or current[-1][0] == current[-1][1] and r[0] == r[1]:
136+
if not current or is_single_char_range(current[-1]) and is_single_char_range(r):
135137
current.append(r)
136138
continue
137139
if len(current) != 0:

0 commit comments

Comments
 (0)