Skip to content

Commit

Permalink
use bytes.Index instead of bytes.Count for checking template string w…
Browse files Browse the repository at this point in the history
…ithout tags

bytes.Index is faster than bytes.Count when the template string contains tags
  • Loading branch information
valyala committed Oct 18, 2022
1 parent 2275c48 commit 2a2d1af
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ func ExecuteFuncString(template, startTag, endTag string, f TagFunc) string {
// but when f returns an error, ExecuteFuncStringWithErr won't panic like ExecuteFuncString
// it just returns an empty string and the error f returned
func ExecuteFuncStringWithErr(template, startTag, endTag string, f TagFunc) (string, error) {
tagsCount := bytes.Count(unsafeString2Bytes(template), unsafeString2Bytes(startTag))
if tagsCount == 0 {
if n := bytes.Index(unsafeString2Bytes(template), unsafeString2Bytes(startTag)); n < 0 {
return template, nil
}

Expand Down

0 comments on commit 2a2d1af

Please sign in to comment.