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:
parent
77e0862827
commit
a9ff9b1bf7
3 changed files with 9 additions and 6 deletions
|
|
@ -562,9 +562,8 @@ func (ms *MemoryStore) GetPlanContext() string {
|
||||||
currentPhase := ms.GetCurrentPhase()
|
currentPhase := ms.GetCurrentPhase()
|
||||||
totalPhases := ms.GetTotalPhases()
|
totalPhases := ms.GetTotalPhases()
|
||||||
|
|
||||||
// Extract task description
|
|
||||||
taskLine := ""
|
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])
|
taskLine = strings.TrimSpace(m[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -660,7 +659,7 @@ func (ms *MemoryStore) FormatPlanDisplay() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
taskLine := ""
|
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])
|
taskLine = strings.TrimSpace(m[1])
|
||||||
}
|
}
|
||||||
status := ms.GetPlanStatus()
|
status := ms.GetPlanStatus()
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sipeed/picoclaw/pkg/utils"
|
"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 := u.Query()
|
||||||
q.Set("q", query)
|
q.Set("q", query)
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
q.Set("limit", fmt.Sprintf("%d", limit))
|
q.Set("limit", strconv.Itoa(limit))
|
||||||
}
|
}
|
||||||
u.RawQuery = q.Encode()
|
u.RawQuery = q.Encode()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,13 @@ import (
|
||||||
"github.com/sipeed/picoclaw/pkg/logger"
|
"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.
|
// IsAudioFile checks if a file is an audio file based on its filename extension and content type.
|
||||||
func IsAudioFile(filename, contentType string) bool {
|
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 {
|
for _, ext := range audioExtensions {
|
||||||
if strings.HasSuffix(strings.ToLower(filename), ext) {
|
if strings.HasSuffix(strings.ToLower(filename), ext) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue