mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Speed up mungedoc TOC by pre-compiling a regex
Brings the time to run the TOC over the docs directory from .7 seconds to .1 seconds
This commit is contained in:
parent
853ea5bab2
commit
22fd8ac32d
@ -57,12 +57,13 @@ func buildTOC(markdown []byte) ([]byte, error) {
|
||||
buffer.WriteString("\n")
|
||||
scanner := bufio.NewScanner(bytes.NewReader(markdown))
|
||||
inBlockQuotes := false
|
||||
blockQuoteRegex, err := regexp.Compile("^```")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
match, err := regexp.Match("^```", []byte(line))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
match := blockQuoteRegex.Match([]byte(line))
|
||||
if match {
|
||||
inBlockQuotes = !inBlockQuotes
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user