refactor: use nil slices and preallocate where capacity is known
This commit is contained in:
parent
e8afd31b28
commit
9300e72e01
5 changed files with 10 additions and 9 deletions
|
|
@ -107,7 +107,7 @@ func (cb *ContextBuilder) buildToolsSection() string {
|
|||
}
|
||||
|
||||
func (cb *ContextBuilder) BuildSystemPrompt() string {
|
||||
parts := []string{}
|
||||
var parts []string
|
||||
|
||||
// Core identity section
|
||||
parts = append(parts, cb.getIdentity())
|
||||
|
|
@ -158,8 +158,6 @@ func (cb *ContextBuilder) LoadBootstrapFiles() string {
|
|||
}
|
||||
|
||||
func (cb *ContextBuilder) BuildMessages(history []providers.Message, summary string, currentMessage string, media []string, channel, chatID string) []providers.Message {
|
||||
messages := []providers.Message{}
|
||||
|
||||
systemPrompt := cb.BuildSystemPrompt()
|
||||
|
||||
// Add Current Session info if provided
|
||||
|
|
@ -200,6 +198,8 @@ func (cb *ContextBuilder) BuildMessages(history []providers.Message, summary str
|
|||
//Diegox-17
|
||||
// --- FIN DEL FIX ---
|
||||
|
||||
messages := make([]providers.Message, 0, len(history)+2)
|
||||
|
||||
messages = append(messages, providers.Message{
|
||||
Role: "system",
|
||||
Content: systemPrompt,
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ func (c *LINEChannel) processEvent(event lineEvent) {
|
|||
|
||||
var content string
|
||||
var mediaPaths []string
|
||||
localFiles := []string{}
|
||||
var localFiles []string
|
||||
|
||||
defer func() {
|
||||
for _, file := range localFiles {
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ func (c *SlackChannel) handleMessageEvent(ev *slackevents.MessageEvent) {
|
|||
content = c.stripBotMention(content)
|
||||
|
||||
var mediaPaths []string
|
||||
localFiles := []string{} // 跟踪需要清理的本地文件
|
||||
var localFiles []string // 跟踪需要清理的本地文件
|
||||
|
||||
// 确保临时文件在函数返回时被清理
|
||||
defer func() {
|
||||
|
|
|
|||
|
|
@ -212,9 +212,9 @@ func (c *TelegramChannel) handleMessage(ctx context.Context, message *telego.Mes
|
|||
chatID := message.Chat.ID
|
||||
c.chatIDs[senderID] = chatID
|
||||
|
||||
content := ""
|
||||
mediaPaths := []string{}
|
||||
localFiles := []string{} // 跟踪需要清理的本地文件
|
||||
var content string
|
||||
var mediaPaths []string
|
||||
var localFiles []string // 跟踪需要清理的本地文件
|
||||
|
||||
// 确保临时文件在函数返回时被清理
|
||||
defer func() {
|
||||
|
|
|
|||
|
|
@ -283,7 +283,8 @@ func PrintPlan(actions []Action, warnings []string) {
|
|||
|
||||
func PrintSummary(result *Result) {
|
||||
fmt.Println()
|
||||
parts := []string{}
|
||||
var parts []string
|
||||
|
||||
if result.FilesCopied > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d files copied", result.FilesCopied))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue