From 644792e18ad749273e10d52943eceb085a0c883a Mon Sep 17 00:00:00 2001 From: beerpsi <92439990+beer-psi@users.noreply.github.com> Date: Fri, 31 Oct 2025 00:47:33 +0700 Subject: [PATCH] Apply suggestions about avoiding allocations Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- core/share.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/share.go b/core/share.go index 530c6e324..98a3ed3ca 100644 --- a/core/share.go +++ b/core/share.go @@ -121,8 +121,20 @@ func (r *shareRepositoryWrapper) Save(entity interface{}) (string, error) { return "", model.ErrNotFound } - if utf8.RuneCountInString(s.Contents) > 30 { - s.Contents = string([]rune(s.Contents)[:26]) + "..." + const maxContentRunes = 30 + const truncateToRunes = 26 + + var runeCount int + var truncateIndex int + for i := range s.Contents { + runeCount++ + if runeCount == truncateToRunes+1 { + truncateIndex = i + } + } + + if runeCount > maxContentRunes { + s.Contents = s.Contents[:truncateIndex] + "..." } id, err = r.Persistable.Save(s)