Skip to content

Commit 89a0542

Browse files
boqishanstefanhaller
authored andcommitted
refactor: use strings.Builder and strings.Repeat to simplify code
Signed-off-by: boqishan <[email protected]>
1 parent 8396747 commit 89a0542

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

pkg/cheatsheet/generate.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,21 @@ func getHeader(binding *types.Binding, tr *i18n.TranslationSet) header {
195195
}
196196

197197
func formatSections(tr *i18n.TranslationSet, bindingSections []*bindingSection) string {
198-
content := fmt.Sprintf("# Lazygit %s\n", tr.Keybindings)
198+
var content strings.Builder
199+
content.WriteString(fmt.Sprintf("# Lazygit %s\n", tr.Keybindings))
199200

200-
content += fmt.Sprintf("\n%s\n", italicize(tr.KeybindingsLegend))
201+
content.WriteString(fmt.Sprintf("\n%s\n", italicize(tr.KeybindingsLegend)))
201202

202203
for _, section := range bindingSections {
203-
content += formatTitle(section.title)
204-
content += "| Key | Action | Info |\n"
205-
content += "|-----|--------|-------------|\n"
204+
content.WriteString(formatTitle(section.title))
205+
content.WriteString("| Key | Action | Info |\n")
206+
content.WriteString("|-----|--------|-------------|\n")
206207
for _, binding := range section.bindings {
207-
content += formatBinding(binding)
208+
content.WriteString(formatBinding(binding))
208209
}
209210
}
210211

211-
return content
212+
return content.String()
212213
}
213214

214215
func formatTitle(title string) string {

pkg/commands/patch/patch_builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ func (p *PatchBuilder) Start(from, to string, reverse bool, canRebase bool) {
6666
}
6767

6868
func (p *PatchBuilder) PatchToApply(reverse bool, turnAddedFilesIntoDiffAgainstEmptyFile bool) string {
69-
patch := ""
69+
var patch strings.Builder
7070

7171
for filename, info := range p.fileInfoMap {
7272
if info.mode == UNSELECTED {
7373
continue
7474
}
7575

76-
patch += p.RenderPatchForFile(RenderPatchForFileOpts{
76+
patch.WriteString(p.RenderPatchForFile(RenderPatchForFileOpts{
7777
Filename: filename,
7878
Plain: true,
7979
Reverse: reverse,
8080
TurnAddedFilesIntoDiffAgainstEmptyFile: turnAddedFilesIntoDiffAgainstEmptyFile,
81-
})
81+
}))
8282
}
8383

84-
return patch
84+
return patch.String()
8585
}
8686

8787
func (p *PatchBuilder) addFileWhole(info *fileInfo) {

pkg/gui/presentation/submodules.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package presentation
22

33
import (
4+
"strings"
5+
46
"github.com/jesseduffield/lazygit/pkg/commands/models"
57
"github.com/jesseduffield/lazygit/pkg/theme"
68
"github.com/samber/lo"
@@ -15,11 +17,11 @@ func GetSubmoduleListDisplayStrings(submodules []*models.SubmoduleConfig) [][]st
1517
func getSubmoduleDisplayStrings(s *models.SubmoduleConfig) []string {
1618
name := s.Name
1719
if s.ParentModule != nil {
18-
indentation := ""
20+
count := 0
1921
for p := s.ParentModule; p != nil; p = p.ParentModule {
20-
indentation += " "
22+
count++
2123
}
22-
24+
indentation := strings.Repeat(" ", count)
2325
name = indentation + "- " + s.Name
2426
}
2527

0 commit comments

Comments
 (0)