Thanks, Chris. I agree to worry about correctness first, but since my
algorithm is very simple I wanted to use it as a chance to learn a bit
about efficient and idiomatic Go.
After some more studying of the relevant packages and discovering the
ellipsis to expand slices to varargs, I think I came up with a
reasonably efficient solution:
func preprocessContent(content []byte) []byte {
newContent := make([]byte, len(content)+200)
for _, line := range bytes.Split(content, []byte{'\n'}) {
if !bytes.HasPrefix(line, []byte(" ")) {
line = linkRE.ReplaceAllFunc(line, linkPages)
}
newContent = append(newContent, line...)
}
// ...