Skip to content

Commit d193494

Browse files
committed
Make RuneWidth faster for code points below 0x0300
1 parent 14e809f commit d193494

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

runewidth.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,19 @@ func NewCondition() *Condition {
101101
// See http://www.unicode.org/reports/tr11/
102102
func (c *Condition) RuneWidth(r rune) int {
103103
switch {
104-
case r < 0 || r > 0x10FFFF || inTables(r, nonprint, combining, notassigned):
104+
case r < 0 || r > 0x10FFFF:
105105
return 0
106-
case (c.EastAsianWidth && IsAmbiguousWidth(r)) || inTables(r, doublewidth):
106+
case c.EastAsianWidth && IsAmbiguousWidth(r):
107+
return 2
108+
// Fast path
109+
case r < 0x0300: // neither combining, non-assigned or double-width
110+
if r <= 0x001F || (0x007F <= r && r <= 0x009F) || r == 0x00AD { // non-printable
111+
return 0
112+
}
113+
return 1
114+
case inTables(r, nonprint, combining, notassigned):
115+
return 0
116+
case inTables(r, doublewidth):
107117
return 2
108118
default:
109119
return 1

0 commit comments

Comments
 (0)