From d16ad40bbfc5b6545453160f742d7f13772bdec4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 18 Sep 2022 10:42:43 +0530 Subject: [PATCH] avoid extra string copy in Stringwidth --- tools/wcswidth/wcswidth.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/wcswidth/wcswidth.go b/tools/wcswidth/wcswidth.go index 5d59ed3b2..1d3f40707 100644 --- a/tools/wcswidth/wcswidth.go +++ b/tools/wcswidth/wcswidth.go @@ -2,6 +2,8 @@ package wcswidth +import "kitty/tools/utils" + func IsFlagCodepoint(ch rune) bool { return 0x1F1E6 <= ch && ch <= 0x1F1FF } @@ -89,5 +91,5 @@ func (self *WCWidthIterator) Parse(b []byte) (ans int) { func Stringwidth(text string) int { w := CreateWCWidthIterator() - return w.Parse([]byte(text)) + return w.Parse(utils.UnsafeStringToBytes(text)) }