diff options
| author | Fuwn <[email protected]> | 2026-02-05 10:39:59 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-05 10:39:59 +0000 |
| commit | 77bbef01943a604fc09e9a422126154988846289 (patch) | |
| tree | 81eb1946475177b82d34e37af48ecfae2d0fa4ca /adapter_go.go | |
| parent | feat(formatter): Dispatch adapter by file extension for multi-language support (diff) | |
| download | iku-77bbef01943a604fc09e9a422126154988846289.tar.xz iku-77bbef01943a604fc09e9a422126154988846289.zip | |
perf: Reduce allocations and syscalls in formatting pipeline
Diffstat (limited to 'adapter_go.go')
| -rw-r--r-- | adapter_go.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/adapter_go.go b/adapter_go.go index 59096bb..1b39e0b 100644 --- a/adapter_go.go +++ b/adapter_go.go @@ -1,11 +1,11 @@ package main import ( + "bytes" "github.com/Fuwn/iku/engine" "go/format" "go/parser" "go/token" - "strings" ) type GoAdapter struct{} @@ -26,11 +26,12 @@ func (a *GoAdapter) Analyze(source []byte) ([]byte, []engine.LineEvent, error) { formatter := &Formatter{} lineInformationMap := formatter.buildLineInfo(tokenFileSet, parsedFile) - sourceLines := strings.Split(string(formattedSource), "\n") - events := make([]engine.LineEvent, len(sourceLines)) + sourceByteLines := bytes.Split(formattedSource, []byte("\n")) + events := make([]engine.LineEvent, len(sourceByteLines)) insideRawString := false - for lineIndex, currentLine := range sourceLines { + for lineIndex, currentLineBytes := range sourceByteLines { + currentLine := string(currentLineBytes) backtickCount := countRawStringDelimiters(currentLine) wasInsideRawString := insideRawString |