text: [API] reduce size of Glyph.Runes to uint16

This shrinks text.Glyph from 72B to 58B.

  LabelStatic/1000runes-RTL-arabic-32   63.62µ ± 0%   62.05µ ± 0%  -2.47% (p=0.002 n=6)

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2023-10-23 21:40:10 +03:00
committed by Chris Waldon
parent 62edabe137
commit df8a8789a3
3 changed files with 11 additions and 11 deletions
+3 -3
View File
@@ -121,7 +121,7 @@ type Glyph struct {
// belongs to. If Flags does not contain FlagClusterBreak, this value will // belongs to. If Flags does not contain FlagClusterBreak, this value will
// always be zero. The final glyph in the cluster contains the runes count // always be zero. The final glyph in the cluster contains the runes count
// for the entire cluster. // for the entire cluster.
Runes int Runes uint16
// Flags encode special properties of this glyph. // Flags encode special properties of this glyph.
Flags Flags Flags Flags
} }
@@ -469,7 +469,7 @@ func (l *Shaper) NextGlyph() (_ Glyph, ok bool) {
Ascent: line.ascent, Ascent: line.ascent,
Descent: line.descent, Descent: line.descent,
Advance: g.xAdvance, Advance: g.xAdvance,
Runes: g.runeCount, Runes: uint16(g.runeCount),
Offset: fixed.Point26_6{ Offset: fixed.Point26_6{
X: g.xOffset, X: g.xOffset,
Y: g.yOffset, Y: g.yOffset,
@@ -505,7 +505,7 @@ func (l *Shaper) NextGlyph() (_ Glyph, ok bool) {
if endOfCluster { if endOfCluster {
glyph.Flags |= FlagClusterBreak glyph.Flags |= FlagClusterBreak
if run.truncator { if run.truncator {
glyph.Runes += l.txt.unreadRuneCount glyph.Runes += uint16(l.txt.unreadRuneCount)
} }
} else { } else {
glyph.Runes = 0 glyph.Runes = 0
+7 -7
View File
@@ -51,9 +51,9 @@ func TestWrappingTruncation(t *testing.T) {
for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() { for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() {
glyphs = append(glyphs, g) glyphs = append(glyphs, g)
if g.Flags&FlagTruncator != 0 && g.Flags&FlagClusterBreak != 0 { if g.Flags&FlagTruncator != 0 && g.Flags&FlagClusterBreak != 0 {
truncatedRunes += g.Runes truncatedRunes += int(g.Runes)
} else { } else {
untruncatedRunes += g.Runes untruncatedRunes += int(g.Runes)
} }
if g.Flags&FlagLineBreak != 0 { if g.Flags&FlagLineBreak != 0 {
lineCount++ lineCount++
@@ -117,9 +117,9 @@ func TestWrappingForcedTruncation(t *testing.T) {
for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() { for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() {
glyphs = append(glyphs, g) glyphs = append(glyphs, g)
if g.Flags&FlagTruncator != 0 && g.Flags&FlagClusterBreak != 0 { if g.Flags&FlagTruncator != 0 && g.Flags&FlagClusterBreak != 0 {
truncatedRunes += g.Runes truncatedRunes += int(g.Runes)
} else { } else {
untruncatedRunes += g.Runes untruncatedRunes += int(g.Runes)
} }
if g.Flags&FlagLineBreak != 0 { if g.Flags&FlagLineBreak != 0 {
lineCount++ lineCount++
@@ -191,9 +191,9 @@ func TestShapingNewlineHandling(t *testing.T) {
for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() { for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() {
glyphs = append(glyphs, g) glyphs = append(glyphs, g)
if g.Flags&FlagTruncator == 0 { if g.Flags&FlagTruncator == 0 {
runes += g.Runes runes += int(g.Runes)
} else { } else {
truncated += g.Runes truncated += int(g.Runes)
} }
} }
if expected := len([]rune(tc.textInput)) - tc.expectedTruncated; expected != runes { if expected := len([]rune(tc.textInput)) - tc.expectedTruncated; expected != runes {
@@ -571,7 +571,7 @@ func TestShapeStringRuneAccounting(t *testing.T) {
} }
totalRunes := 0 totalRunes := 0
for _, g := range glyphs { for _, g := range glyphs {
totalRunes += g.Runes totalRunes += int(g.Runes)
} }
if inputRunes := len([]rune(tc.input)); totalRunes != inputRunes { if inputRunes := len([]rune(tc.input)); totalRunes != inputRunes {
t.Errorf("input contained %d runes, but glyphs contained %d", inputRunes, totalRunes) t.Errorf("input contained %d runes, but glyphs contained %d", inputRunes, totalRunes)
+1 -1
View File
@@ -138,7 +138,7 @@ func (it *textIterator) processGlyph(g text.Glyph, ok bool) (_ text.Glyph, visib
if it.maxLines > 0 { if it.maxLines > 0 {
if g.Flags&text.FlagTruncator != 0 && g.Flags&text.FlagClusterBreak != 0 { if g.Flags&text.FlagTruncator != 0 && g.Flags&text.FlagClusterBreak != 0 {
// A glyph carrying both of these flags provides the count of truncated runes. // A glyph carrying both of these flags provides the count of truncated runes.
it.truncated = g.Runes it.truncated = int(g.Runes)
} }
if g.Flags&text.FlagLineBreak != 0 { if g.Flags&text.FlagLineBreak != 0 {
it.linesSeen++ it.linesSeen++