Skip to content

Commit

Permalink
fix: optimize speed of retrieving user/group widths
Browse files Browse the repository at this point in the history
  • Loading branch information
owallb committed Sep 14, 2024
1 parent 1c56620 commit 299628e
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,12 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
var groupWidth int

// Only fetch user/group widths if configured to display them
iterInfo:
for _, s := range getInfo(dir.path) {
switch s {
case "user":
userWidth = getUserWidth(dir, beg, end)
case "group":
groupWidth = getGroupWidth(dir, beg, end)
}

if userWidth > 0 && groupWidth > 0 {
break
case "user", "group":
userWidth, groupWidth = getUserGroupWidth(dir, beg, end)
break iterInfo
}
}

Expand Down Expand Up @@ -542,24 +538,16 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
}
}

func getUserWidth(dir *dir, beg int, end int) int {
maxw := 0

for _, f := range dir.files[beg:end] {
maxw = max(len(userName(f.FileInfo)), maxw)
}

return maxw
}

func getGroupWidth(dir *dir, beg int, end int) int {
maxw := 0
func getUserGroupWidth(dir *dir, beg int, end int) (int, int) {
userMaxw := 0
groupMaxw := 0

for _, f := range dir.files[beg:end] {
maxw = max(len(groupName(f.FileInfo)), maxw)
userMaxw = max(len(userName(f.FileInfo)), userMaxw)
groupMaxw = max(len(userName(f.FileInfo)), groupMaxw)
}

return maxw
return userMaxw, groupMaxw
}

func getWidths(wtot int) []int {
Expand Down

0 comments on commit 299628e

Please sign in to comment.