Skip to content

Commit

Permalink
Remove redundant len check in GroupSheets and UngroupSheets
Browse files Browse the repository at this point in the history
From the Go specification [1]:

  "1. For a nil slice, the number of iterations is 0."

`len` returns 0 if the slice or map is nil [2]. Therefore, checking
`len(v) > 0` around a loop is unnecessary.

[1]: https://go.dev/ref/spec#For_range
[2]: https://pkg.go.dev/builtin#len

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee committed Oct 6, 2023
1 parent 07f2c68 commit ef25aef
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1739,11 +1739,8 @@ func (f *File) GroupSheets(sheets []string) error {
}
for _, ws := range wss {
sheetViews := ws.SheetViews.SheetView
if len(sheetViews) > 0 {
for idx := range sheetViews {
ws.SheetViews.SheetView[idx].TabSelected = true
}
continue
for idx := range sheetViews {
ws.SheetViews.SheetView[idx].TabSelected = true
}
}
return nil
Expand All @@ -1758,10 +1755,8 @@ func (f *File) UngroupSheets() error {
}
ws, _ := f.workSheetReader(sheet)
sheetViews := ws.SheetViews.SheetView
if len(sheetViews) > 0 {
for idx := range sheetViews {
ws.SheetViews.SheetView[idx].TabSelected = false
}
for idx := range sheetViews {
ws.SheetViews.SheetView[idx].TabSelected = false
}
}
return nil
Expand Down

0 comments on commit ef25aef

Please sign in to comment.