Skip to content

Commit

Permalink
Make RuneWidth faster for code points below 0x0300
Browse files Browse the repository at this point in the history
  • Loading branch information
p-e-w committed Jun 12, 2020
1 parent 14e809f commit d193494
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions runewidth.go
Expand Up @@ -101,9 +101,19 @@ func NewCondition() *Condition {
// See http://www.unicode.org/reports/tr11/
func (c *Condition) RuneWidth(r rune) int {
switch {
case r < 0 || r > 0x10FFFF || inTables(r, nonprint, combining, notassigned):
case r < 0 || r > 0x10FFFF:
return 0
case (c.EastAsianWidth && IsAmbiguousWidth(r)) || inTables(r, doublewidth):
case c.EastAsianWidth && IsAmbiguousWidth(r):
return 2
// Fast path
case r < 0x0300: // neither combining, non-assigned or double-width
if r <= 0x001F || (0x007F <= r && r <= 0x009F) || r == 0x00AD { // non-printable
return 0
}
return 1
case inTables(r, nonprint, combining, notassigned):
return 0
case inTables(r, doublewidth):
return 2
default:
return 1
Expand Down

0 comments on commit d193494

Please sign in to comment.