From: Bjørn Erik Pedersen Date: Tue, 20 Apr 2021 14:50:03 +0000 (+0200) Subject: publisher: Some performance tweaks for the HTML elements collector X-Git-Tag: v0.83.0~38 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=ef34dd8f0e94e52ba6f1d5d607e4ac3ae98a7abb;p=brevno-suite%2Fhugo publisher: Some performance tweaks for the HTML elements collector --- diff --git a/publisher/htmlElementsCollector.go b/publisher/htmlElementsCollector.go index 9f4be1ff..13387a7e 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
,