mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +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:
		@@ -57,12 +57,13 @@ func buildTOC(markdown []byte) ([]byte, error) {
 | 
				
			|||||||
	buffer.WriteString("\n")
 | 
						buffer.WriteString("\n")
 | 
				
			||||||
	scanner := bufio.NewScanner(bytes.NewReader(markdown))
 | 
						scanner := bufio.NewScanner(bytes.NewReader(markdown))
 | 
				
			||||||
	inBlockQuotes := false
 | 
						inBlockQuotes := false
 | 
				
			||||||
	for scanner.Scan() {
 | 
						blockQuoteRegex, err := regexp.Compile("^```")
 | 
				
			||||||
		line := scanner.Text()
 | 
					 | 
				
			||||||
		match, err := regexp.Match("^```", []byte(line))
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						for scanner.Scan() {
 | 
				
			||||||
 | 
							line := scanner.Text()
 | 
				
			||||||
 | 
							match := blockQuoteRegex.Match([]byte(line))
 | 
				
			||||||
		if match {
 | 
							if match {
 | 
				
			||||||
			inBlockQuotes = !inBlockQuotes
 | 
								inBlockQuotes = !inBlockQuotes
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user