Skip to content

Commit 07edb85

Browse files
committed
refine
1 parent 31930dd commit 07edb85

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

rich/cells.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,22 @@ def get_character_cell_size(character: str, unicode_version: str = "auto") -> in
5959
return 0
6060
table = load_cell_table(unicode_version).widths
6161

62-
# Fast path: codepoint beyond table range
6362
last_entry = table[-1]
6463
if codepoint > last_entry[1]:
6564
return 1
6665

67-
# Binary search with fewer tuple unpacks
6866
lower_bound = 0
6967
upper_bound = len(table) - 1
7068

7169
while lower_bound <= upper_bound:
7270
index = (lower_bound + upper_bound) >> 1
73-
entry = table[index]
74-
start = entry[0]
75-
71+
start, end, width = table[index]
7672
if codepoint < start:
7773
upper_bound = index - 1
78-
elif codepoint > entry[1]: # end
74+
elif codepoint > end:
7975
lower_bound = index + 1
8076
else:
81-
# Found: codepoint is in range [start, end]
82-
return entry[2]
83-
77+
return width
8478
return 1
8579

8680

0 commit comments

Comments
 (0)