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 <noreply@anthropic.com>
This commit is contained in:
dj-oyu 2026-02-24 15:44:18 +09:00
parent d167c94cdd
commit 032f40a592
3 changed files with 9 additions and 6 deletions

View file

@ -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()

View file

@ -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()

View file

@ -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) {