From 4d59d109d1bfd655af7f7e6b0675e60bbdecd9d2 Mon Sep 17 00:00:00 2001 From: Teddy Sommavilla Date: Mon, 22 Jan 2024 15:12:48 +0100 Subject: [PATCH] refactor: use unsafe to avoid alloc --- vimebu.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vimebu.go b/vimebu.go index 8edb9bf..07753e6 100644 --- a/vimebu.go +++ b/vimebu.go @@ -6,6 +6,7 @@ import ( "log" "strconv" "strings" + "unsafe" ) const ( @@ -251,5 +252,10 @@ func (b *Builder) String() string { if b.flLabel { b.underlying.WriteByte(rightBracketByte) } - return b.underlying.String() + + return b.unsafeString() +} + +func (b *Builder) unsafeString() string { + return unsafe.String(unsafe.SliceData(b.underlying.Bytes()), b.underlying.Len()) }