Large syntax highlighting memory optimization

Ref #634
This commit is contained in:
Zachary Yedidia
2018-01-29 15:21:00 -05:00
parent 0913a1aeb3
commit fddf1690e3
3 changed files with 103 additions and 41 deletions

View File

@@ -23,6 +23,20 @@ func Count(s string) int {
return utf8.RuneCountInString(s)
}
// Convert byte array to rune array
func toRunes(b []byte) []rune {
runes := make([]rune, 0, utf8.RuneCount(b))
for len(b) > 0 {
r, size := utf8.DecodeRune(b)
runes = append(runes, r)
b = b[size:]
}
return runes
}
// NumOccurrences counts the number of occurrences of a byte in a string
func NumOccurrences(s string, c byte) int {
var n int