mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-21 08:17:15 +09:00
Make determining whether a code point represents a combining mark faster (#1719)
This commit is contained in:
committed by
GitHub
parent
efb38b8636
commit
5ce26cca71
@@ -5,6 +5,16 @@ import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
var minMark = rune(unicode.Mark.R16[0].Lo)
|
||||
|
||||
func isMark(r rune) bool {
|
||||
// Fast path
|
||||
if r < minMark {
|
||||
return false
|
||||
}
|
||||
return unicode.In(r, unicode.Mark)
|
||||
}
|
||||
|
||||
// DecodeCharacter returns the next character from an array of bytes
|
||||
// A character is a rune along with any accompanying combining runes
|
||||
func DecodeCharacter(b []byte) (rune, []rune, int) {
|
||||
@@ -13,7 +23,7 @@ func DecodeCharacter(b []byte) (rune, []rune, int) {
|
||||
c, s := utf8.DecodeRune(b)
|
||||
|
||||
var combc []rune
|
||||
for unicode.In(c, unicode.Mark) {
|
||||
for isMark(c) {
|
||||
combc = append(combc, c)
|
||||
size += s
|
||||
|
||||
@@ -32,7 +42,7 @@ func DecodeCharacterInString(str string) (rune, []rune, int) {
|
||||
c, s := utf8.DecodeRuneInString(str)
|
||||
|
||||
var combc []rune
|
||||
for unicode.In(c, unicode.Mark) {
|
||||
for isMark(c) {
|
||||
combc = append(combc, c)
|
||||
size += s
|
||||
|
||||
@@ -50,7 +60,7 @@ func CharacterCount(b []byte) int {
|
||||
|
||||
for len(b) > 0 {
|
||||
r, size := utf8.DecodeRune(b)
|
||||
if !unicode.In(r, unicode.Mark) {
|
||||
if !isMark(r) {
|
||||
s++
|
||||
}
|
||||
|
||||
@@ -66,7 +76,7 @@ func CharacterCountInString(str string) int {
|
||||
s := 0
|
||||
|
||||
for _, r := range str {
|
||||
if !unicode.In(r, unicode.Mark) {
|
||||
if !isMark(r) {
|
||||
s++
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user