summaryrefslogtreecommitdiffstats
path: root/publisher
diff options
context:
space:
mode:
Diffstat (limited to 'publisher')
-rw-r--r--publisher/htmlElementsCollector.go4
-rw-r--r--publisher/htmlElementsCollector_test.go27
2 files changed, 30 insertions, 1 deletions
diff --git a/publisher/htmlElementsCollector.go b/publisher/htmlElementsCollector.go
index e2f8fd2ca..b9b0f4e11 100644
--- a/publisher/htmlElementsCollector.go
+++ b/publisher/htmlElementsCollector.go
@@ -122,12 +122,14 @@ func (w *cssClassCollectorWriter) Write(p []byte) (n int, err error) {
continue
}
+ key := s
+
s, tagName := w.insertStandinHTMLElement(s)
el := parseHTMLElement(s)
el.Tag = tagName
w.collector.mu.Lock()
- w.collector.elementSet[s] = true
+ w.collector.elementSet[key] = true
if el.Tag != "" {
w.collector.elements = append(w.collector.elements, el)
}
diff --git a/publisher/htmlElementsCollector_test.go b/publisher/htmlElementsCollector_test.go
index 6b5ef9863..ab1529288 100644
--- a/publisher/htmlElementsCollector_test.go
+++ b/publisher/htmlElementsCollector_test.go
@@ -99,3 +99,30 @@ func TestClassCollector(t *testing.T) {
}
}
+
+func BenchmarkClassCollectorWriter(b *testing.B) {
+ const benchHTML = `
+<html>
+<body id="i1" class="a b c d">
+<a class="c d e"></a>
+<br>
+<a class="c d e"></a>
+<a class="c d e"></a>
+<br>
+<a id="i2" class="c d e f"></a>
+<a id="i3" class="c d e"></a>
+<a class="c d e"></a>
+<br>
+<a class="c d e"></a>
+<a class="c d e"></a>
+<a class="c d e"></a>
+<a class="c d e"></a>
+</body>
+</html>
+`
+ for i := 0; i < b.N; i++ {
+ w := newHTMLElementsCollectorWriter(newHTMLElementsCollector())
+ fmt.Fprint(w, benchHTML)
+
+ }
+}