From 10d7c513c47441f9260946ecc4ccc80cdbb966d9 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 10 Oct 2023 19:50:04 +0200 Subject: Don’t use lambdas, and just use a damn for-loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- formatter/formatter.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/formatter/formatter.go b/formatter/formatter.go index 633c067..b8ec85f 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -2,7 +2,6 @@ package formatter import ( "fmt" - "slices" "unicode" "git.thomasvoss.com/gsp/parser" @@ -48,14 +47,16 @@ func PrintAst(ast parser.AstNode) { } func printAttrs(attrs []parser.Attr) { - classes := make([]parser.Attr, len(attrs), cap(attrs)) - copy(classes, attrs) - classes = slices.DeleteFunc(classes, func(a parser.Attr) bool { - return a.Key != "class" - }) - attrs = slices.DeleteFunc(attrs, func(a parser.Attr) bool { - return a.Key == "class" - }) + classes := make([]parser.Attr, 0, cap(attrs)) + nClasses := make([]parser.Attr, 0, cap(attrs)) + + for _, a := range attrs { + if a.Key == "class" { + classes = append(classes, a) + } else { + nClasses = append(nClasses, a) + } + } if len(classes) > 0 { fmt.Print(" class=\"") -- cgit v1.2.3