Summary
rewriteContents calls rewriteFile(f.Path, []byte(fr.find), []byte(fr.replace), info.Mode()). The string → []byte conversion allocates per file. On a tree of N files we allocate N copies of the same find/replace bytes.
Trivially fixable: convert once when constructing findReplace (or store both forms).
Impact (Performance: Low)
- Two small allocations per file. Negligible per file but observable on large trees.
Suggested Fix
Pre-compute []byte versions in the findReplace struct (or change find/replace field types to []byte).
Files
Summary
rewriteContentscallsrewriteFile(f.Path, []byte(fr.find), []byte(fr.replace), info.Mode()). Thestring→[]byteconversion allocates per file. On a tree of N files we allocate N copies of the same find/replace bytes.Trivially fixable: convert once when constructing
findReplace(or store both forms).Impact (Performance: Low)
Suggested Fix
Pre-compute
[]byteversions in thefindReplacestruct (or changefind/replacefield types to[]byte).Files
find_replace.go:101-120