From a9ff9b1bf7a1f73d5ade92230a0b5d4890b3effc Mon Sep 17 00:00:00 2001 From: dj-oyu <68707227+dj-oyu@users.noreply.github.com> Date: Tue, 24 Feb 2026 15:44:18 +0900 Subject: [PATCH] perf: hoist per-call allocations to package-level variables - Move audioExtensions/audioTypes slices to package var in media.go - Use strconv.Itoa instead of fmt.Sprintf for int conversion - Replace inline regexp.MustCompile with existing reTaskLine var Co-Authored-By: Claude Opus 4.6 --- pkg/agent/memory.go | 5 ++--- pkg/skills/clawhub_registry.go | 3 ++- pkg/utils/media.go | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/agent/memory.go b/pkg/agent/memory.go index 9069bdc9c..46afed9ba 100644 --- a/pkg/agent/memory.go +++ b/pkg/agent/memory.go @@ -562,9 +562,8 @@ func (ms *MemoryStore) GetPlanContext() string { currentPhase := ms.GetCurrentPhase() totalPhases := ms.GetTotalPhases() - // Extract task description taskLine := "" - if m := regexp.MustCompile(`(?m)^> Task:\s*(.+)`).FindStringSubmatch(content); len(m) >= 2 { + if m := reTaskLine.FindStringSubmatch(content); len(m) >= 2 { taskLine = strings.TrimSpace(m[1]) } @@ -660,7 +659,7 @@ func (ms *MemoryStore) FormatPlanDisplay() string { } taskLine := "" - if m := regexp.MustCompile(`(?m)^> Task:\s*(.+)`).FindStringSubmatch(content); len(m) >= 2 { + if m := reTaskLine.FindStringSubmatch(content); len(m) >= 2 { taskLine = strings.TrimSpace(m[1]) } status := ms.GetPlanStatus() diff --git a/pkg/skills/clawhub_registry.go b/pkg/skills/clawhub_registry.go index f78197bbe..2103bdc52 100644 --- a/pkg/skills/clawhub_registry.go +++ b/pkg/skills/clawhub_registry.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "os" + "strconv" "time" "github.com/sipeed/picoclaw/pkg/utils" @@ -111,7 +112,7 @@ func (c *ClawHubRegistry) Search(ctx context.Context, query string, limit int) ( q := u.Query() q.Set("q", query) if limit > 0 { - q.Set("limit", fmt.Sprintf("%d", limit)) + q.Set("limit", strconv.Itoa(limit)) } u.RawQuery = q.Encode() diff --git a/pkg/utils/media.go b/pkg/utils/media.go index a34889fb8..0092d1de4 100644 --- a/pkg/utils/media.go +++ b/pkg/utils/media.go @@ -13,10 +13,13 @@ import ( "github.com/sipeed/picoclaw/pkg/logger" ) +var ( + audioExtensions = []string{".mp3", ".wav", ".ogg", ".m4a", ".flac", ".aac", ".wma"} + audioTypes = []string{"audio/", "application/ogg", "application/x-ogg"} +) + // IsAudioFile checks if a file is an audio file based on its filename extension and content type. func IsAudioFile(filename, contentType string) bool { - audioExtensions := []string{".mp3", ".wav", ".ogg", ".m4a", ".flac", ".aac", ".wma"} - audioTypes := []string{"audio/", "application/ogg", "application/x-ogg"} for _, ext := range audioExtensions { if strings.HasSuffix(strings.ToLower(filename), ext) {