aboutsummaryrefslogtreecommitdiff
path: root/adapter_go.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-05 10:39:59 +0000
committerFuwn <[email protected]>2026-02-05 10:39:59 +0000
commit77bbef01943a604fc09e9a422126154988846289 (patch)
tree81eb1946475177b82d34e37af48ecfae2d0fa4ca /adapter_go.go
parentfeat(formatter): Dispatch adapter by file extension for multi-language support (diff)
downloadiku-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.go9
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