mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
refactor: use strings.Builder and strings.Repeat to simplify code (#5068)
### PR Description strings.Builder has fewer memory allocations and better performance. More info: [golang/go#75190](https://github.com/golang/go/issues/75190)
This commit is contained in:
commit
06426b2107
|
|
@ -195,20 +195,21 @@ func getHeader(binding *types.Binding, tr *i18n.TranslationSet) header {
|
|||
}
|
||||
|
||||
func formatSections(tr *i18n.TranslationSet, bindingSections []*bindingSection) string {
|
||||
content := fmt.Sprintf("# Lazygit %s\n", tr.Keybindings)
|
||||
var content strings.Builder
|
||||
content.WriteString(fmt.Sprintf("# Lazygit %s\n", tr.Keybindings))
|
||||
|
||||
content += fmt.Sprintf("\n%s\n", italicize(tr.KeybindingsLegend))
|
||||
content.WriteString(fmt.Sprintf("\n%s\n", italicize(tr.KeybindingsLegend)))
|
||||
|
||||
for _, section := range bindingSections {
|
||||
content += formatTitle(section.title)
|
||||
content += "| Key | Action | Info |\n"
|
||||
content += "|-----|--------|-------------|\n"
|
||||
content.WriteString(formatTitle(section.title))
|
||||
content.WriteString("| Key | Action | Info |\n")
|
||||
content.WriteString("|-----|--------|-------------|\n")
|
||||
for _, binding := range section.bindings {
|
||||
content += formatBinding(binding)
|
||||
content.WriteString(formatBinding(binding))
|
||||
}
|
||||
}
|
||||
|
||||
return content
|
||||
return content.String()
|
||||
}
|
||||
|
||||
func formatTitle(title string) string {
|
||||
|
|
|
|||
|
|
@ -66,22 +66,22 @@ func (p *PatchBuilder) Start(from, to string, reverse bool, canRebase bool) {
|
|||
}
|
||||
|
||||
func (p *PatchBuilder) PatchToApply(reverse bool, turnAddedFilesIntoDiffAgainstEmptyFile bool) string {
|
||||
patch := ""
|
||||
var patch strings.Builder
|
||||
|
||||
for filename, info := range p.fileInfoMap {
|
||||
if info.mode == UNSELECTED {
|
||||
continue
|
||||
}
|
||||
|
||||
patch += p.RenderPatchForFile(RenderPatchForFileOpts{
|
||||
patch.WriteString(p.RenderPatchForFile(RenderPatchForFileOpts{
|
||||
Filename: filename,
|
||||
Plain: true,
|
||||
Reverse: reverse,
|
||||
TurnAddedFilesIntoDiffAgainstEmptyFile: turnAddedFilesIntoDiffAgainstEmptyFile,
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
return patch
|
||||
return patch.String()
|
||||
}
|
||||
|
||||
func (p *PatchBuilder) addFileWhole(info *fileInfo) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package presentation
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||
"github.com/samber/lo"
|
||||
|
|
@ -15,11 +17,11 @@ func GetSubmoduleListDisplayStrings(submodules []*models.SubmoduleConfig) [][]st
|
|||
func getSubmoduleDisplayStrings(s *models.SubmoduleConfig) []string {
|
||||
name := s.Name
|
||||
if s.ParentModule != nil {
|
||||
indentation := ""
|
||||
count := 0
|
||||
for p := s.ParentModule; p != nil; p = p.ParentModule {
|
||||
indentation += " "
|
||||
count++
|
||||
}
|
||||
|
||||
indentation := strings.Repeat(" ", count)
|
||||
name = indentation + "- " + s.Name
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue