diff --git a/pkg/channels/telegram.go b/pkg/channels/telegram.go index cb10e3a64..c422e9fec 100644 --- a/pkg/channels/telegram.go +++ b/pkg/channels/telegram.go @@ -833,7 +833,7 @@ func extractInlineCodes(text string) inlineCodeMatch { func extractMarkdownTables(text string) tableBlockMatch { lines := strings.Split(text, "\n") out := make([]string, 0, len(lines)) - tables := make([]string, 0) + tables := make([]string, 0, 4) placeholderIdx := 0 for i := 0; i < len(lines); { @@ -845,7 +845,7 @@ func extractMarkdownTables(text string) tableBlockMatch { } block := lines[start:i] formatted := formatMarkdownTable(block) - placeholder := fmt.Sprintf("\x00TB%d\x00", placeholderIdx) + placeholder := "\x00TB" + strconv.Itoa(placeholderIdx) + "\x00" placeholderIdx++ tables = append(tables, formatted) out = append(out, placeholder) diff --git a/pkg/config/config.go b/pkg/config/config.go index 003b2438a..7ac337856 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -625,7 +625,7 @@ func (c *Config) GetModelConfig(modelName string) (*ModelConfig, error) { // findMatches finds all ModelConfig entries with the given model_name. func (c *Config) findMatches(modelName string) []ModelConfig { - var matches []ModelConfig + matches := make([]ModelConfig, 0, 4) for i := range c.ModelList { if c.ModelList[i].ModelName == modelName { matches = append(matches, c.ModelList[i]) diff --git a/pkg/config/migration.go b/pkg/config/migration.go index 30eaa7474..d23331bfe 100644 --- a/pkg/config/migration.go +++ b/pkg/config/migration.go @@ -45,7 +45,7 @@ func ConvertProvidersToModelList(cfg *Config) []ModelConfig { p := cfg.Providers - var result []ModelConfig + result := make([]ModelConfig, 0, 20) // Track if we've applied the legacy model name fix (only for first provider) legacyModelNameApplied := false diff --git a/pkg/skills/loader.go b/pkg/skills/loader.go index e71ae5201..c27301780 100644 --- a/pkg/skills/loader.go +++ b/pkg/skills/loader.go @@ -70,7 +70,7 @@ func NewSkillsLoader(workspace string, globalSkills string, builtinSkills string } func (sl *SkillsLoader) ListSkills() []SkillInfo { - skills := make([]SkillInfo, 0) + skills := make([]SkillInfo, 0, 20) if sl.workspaceSkills != "" { if dirs, err := os.ReadDir(sl.workspaceSkills); err == nil { diff --git a/pkg/skills/registry.go b/pkg/skills/registry.go index 45ae72253..5cc9ac0a9 100644 --- a/pkg/skills/registry.go +++ b/pkg/skills/registry.go @@ -180,7 +180,7 @@ func (rm *RegistryManager) SearchAll(ctx context.Context, query string, limit in close(resultsCh) }() - var merged []SearchResult + merged := make([]SearchResult, 0, len(regs)*limit) var lastErr error var anyRegistrySucceeded bool diff --git a/pkg/skills/search_cache.go b/pkg/skills/search_cache.go index 5d7d2797e..480e1bd11 100644 --- a/pkg/skills/search_cache.go +++ b/pkg/skills/search_cache.go @@ -39,8 +39,8 @@ func NewSearchCache(maxEntries int, ttl time.Duration) *SearchCache { ttl = 5 * time.Minute } return &SearchCache{ - entries: make(map[string]*cacheEntry), - order: make([]string, 0), + entries: make(map[string]*cacheEntry, maxEntries), + order: make([]string, 0, maxEntries), maxEntries: maxEntries, ttl: ttl, }