text/v2: use RuneLen instead of DecodeRuneInString for performance

This commit is contained in:
Hajime Hoshi
2025-06-09 00:29:09 +09:00
parent 95d47b04a9
commit a034565163
2 changed files with 3 additions and 3 deletions

View File

@@ -171,7 +171,7 @@ func (g *GoXFace) appendGlyphsForLine(glyphs []Glyph, line string, indexOffset i
// Adjust the position to the integers.
// The current glyph images assume that they are rendered on integer positions so far.
_, size := utf8.DecodeRuneInString(line[i:])
size := utf8.RuneLen(r)
// Append a glyph even if img is nil.
// This is necessary to return index information for control characters.

View File

@@ -166,9 +166,9 @@ type textChunk struct {
func (m *MultiFace) splitText(text string) iter.Seq[textChunk] {
return func(yield func(textChunk) bool) {
var chunk textChunk
for ri, r := range text {
for _, r := range text {
fi := -1
_, l := utf8.DecodeRuneInString(text[ri:])
l := utf8.RuneLen(r)
for i, f := range m.faces {
if !f.hasGlyph(r) && i < len(m.faces)-1 {
continue