perf: 根据golangci检测结果,优化部分代码

This commit is contained in:
mh-swift
2024-07-09 17:32:52 +08:00
parent 5c3bcaf6cc
commit 9133afb864
6 changed files with 32 additions and 27 deletions

View File

@@ -103,7 +103,7 @@ func (e *tagElement) write(bf *formattedBuffer, isPreviousNodeInline bool) bool
}
}
if e.isInline() || bytes.IndexAny(condensedBuffer.buffer.Bytes()[1:], "\n") == -1 {
if e.isInline() || bytes.ContainsAny(condensedBuffer.buffer.Bytes()[1:], "\n") {
// If we're an inline tag, or there were no newlines were in the buffer,
// replace the original with the condensed version
condensedBuffer.buffer = bytes.NewBuffer(bytes.Join([][]byte{

View File

@@ -97,5 +97,5 @@ func (bf *formattedBuffer) writeToken(token string, kind formatterTokenType) {
// unifyLineFeed unifies line feeds.
func unifyLineFeed(s string) string {
return strings.Replace(strings.Replace(s, "\r\n", "\n", -1), "\r", "\n", -1)
return strings.ReplaceAll(strings.ReplaceAll(s, "\r\n", "\n"), "\r", "\n")
}