Reduced memory allocations

This commit is contained in:
Eduard Urbach 2024-07-17 21:09:01 +02:00
parent 68e21c96e3
commit f617e115cd
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -1,6 +1,9 @@
package token package token
import "fmt" import (
"fmt"
"unsafe"
)
// Token represents a single element in a source file. // Token represents a single element in a source file.
// The characters that make up an identifier are grouped into a single token. // The characters that make up an identifier are grouped into a single token.
@ -30,5 +33,5 @@ func (t *Token) Reset() {
// Text returns the token text. // Text returns the token text.
func (t *Token) Text() string { func (t *Token) Text() string {
return string(t.Bytes) return unsafe.String(unsafe.SliceData(t.Bytes), len(t.Bytes))
} }