From ef34dd8f0e94e52ba6f1d5d607e4ac3ae98a7abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 20 Apr 2021 16:50:03 +0200 Subject: publisher: Some performance tweaks for the HTML elements collector --- publisher/htmlElementsCollector.go | 80 ++++++++++++++++++++------------- publisher/htmlElementsCollector_test.go | 70 +---------------------------- 2 files changed, 49 insertions(+), 101 deletions(-) (limited to 'publisher') diff --git a/publisher/htmlElementsCollector.go b/publisher/htmlElementsCollector.go index 9f4be1ff5..13387a7ee 100644 --- a/publisher/htmlElementsCollector.go +++ b/publisher/htmlElementsCollector.go @@ -108,13 +108,13 @@ func newHTMLElementsCollectorWriter(collector *htmlElementsCollector) *htmlEleme } } -// Write splits the incoming stream into single html element and writes these into elementSet +// Write splits the incoming stream into single html element. func (w *htmlElementsCollectorWriter) Write(p []byte) (n int, err error) { n = len(p) i := 0 for i < len(p) { - // if is not collecting, cycle through byte stream until start bracket "<" is found + // If we are not collecting, cycle through byte stream until start bracket "<" is found. if !w.isCollecting { for ; i < len(p); i++ { b := p[i] @@ -126,9 +126,9 @@ func (w *htmlElementsCollectorWriter) Write(p []byte) (n int, err error) { } if w.isCollecting { - // if is collecting, cycle through byte stream until end bracket ">" is found - // disregard any ">" if within a quote - // write bytes until found to buffer + // If we are collecting, cycle through byte stream until end bracket ">" is found, + // disregard any ">" if within a quote, + // write bytes until found to buffer. for ; i < len(p); i++ { b := p[i] w.toggleIfQuote(b) @@ -141,54 +141,69 @@ func (w *htmlElementsCollectorWriter) Write(p []byte) (n int, err error) { } } - // if no end bracket ">" is found while collecting, but the stream ended + // If no end bracket ">" is found while collecting, but the stream ended // this could mean we received chunks of a stream from e.g. the minify functionality - // next if loop will be skipped + // next if loop will be skipped. - // at this point we have collected an element line between angle brackets "<" and ">" + // At this point we have collected an element line between angle brackets "<" and ">". if !w.isCollecting { - s := w.buff.String() - w.buff.Reset() - - // filter out unwanted tags - // empty string, just in case - // if within preformatted code blocks
,