Merge pull request #552 from jvoisin/spaceclass

perf: replace regex+Split with strings.Fields in getClassesSlice
This commit is contained in:
Martin Angers
2026-05-26 09:12:25 -04:00
committed by GitHub
2 changed files with 20 additions and 1 deletions
+19
View File
@@ -49,3 +49,22 @@ func BenchmarkHtml(b *testing.B) {
_, _ = sel.Html()
}
}
func BenchmarkAddClass(b *testing.B) {
b.StopTimer()
sel := DocW().Find("li")
b.StartTimer()
for i := 0; i < b.N; i++ {
sel.AddClass("foo bar baz")
}
}
func BenchmarkRemoveClass(b *testing.B) {
b.StopTimer()
sel := DocW().Find("li")
sel.AddClass("foo bar baz")
b.StartTimer()
for i := 0; i < b.N; i++ {
sel.RemoveClass("foo bar baz")
}
}
+1 -1
View File
@@ -255,7 +255,7 @@ func getClassesAndAttr(n *html.Node, create bool) (classes string, attr *html.At
}
func getClassesSlice(classes string) []string {
return strings.Split(classTrimReplacer.Replace(" "+classes+" "), " ")
return strings.Fields(classes)
}
func removeAttr(n *html.Node, attrName string) {