mirror of
https://github.com/PuerkitoBio/goquery.git
synced 2026-10-19 16:15:33 +00:00
Merge pull request #552 from jvoisin/spaceclass
perf: replace regex+Split with strings.Fields in getClassesSlice
This commit is contained in:
@@ -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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user