From f0b8454de1f81c99af892476544358f8b78c9e6a Mon Sep 17 00:00:00 2001 From: Eng Zer Jun Date: Sun, 21 May 2023 01:30:42 +0800 Subject: [PATCH] perf: avoid unnecessary byte/string conversion We can use alternative functions/methods to avoid unnecessary byte/string conversion calls. Signed-off-by: Eng Zer Jun --- numfmt.go | 2 +- table.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/numfmt.go b/numfmt.go index cea63a1ad9..57aa8c8ed1 100644 --- a/numfmt.go +++ b/numfmt.go @@ -1220,7 +1220,7 @@ func printCommaSep(text string) string { if i > 0 && (length-i)%3 == 0 { target.WriteString(",") } - target.WriteString(string(text[i])) + target.WriteByte(text[i]) } if len(subStr) == 2 { target.WriteString(".") diff --git a/table.go b/table.go index 8b375a8a3f..094f765927 100644 --- a/table.go +++ b/table.go @@ -490,7 +490,7 @@ func (f *File) parseFilterExpression(expression string, tokens []string) ([]int, // expressions). conditional := 0 c := tokens[3] - if conditionFormat.Match([]byte(c)) { + if conditionFormat.MatchString(c) { conditional = 1 } expression1, token1, err := f.parseFilterTokens(expression, tokens[:3]) @@ -538,7 +538,7 @@ func (f *File) parseFilterTokens(expression string, tokens []string) ([]int, str } token := tokens[2] // Special handling for Blanks/NonBlanks. - re := blankFormat.Match([]byte(strings.ToLower(token))) + re := blankFormat.MatchString((strings.ToLower(token))) if re { // Only allow Equals or NotEqual in this context. if operator != 2 && operator != 5 { @@ -563,7 +563,7 @@ func (f *File) parseFilterTokens(expression string, tokens []string) ([]int, str } // If the string token contains an Excel match character then change the // operator type to indicate a non "simple" equality. - re = matchFormat.Match([]byte(token)) + re = matchFormat.MatchString(token) if operator == 2 && re { operator = 22 }