mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-02 23:27:22 -04:00
Optimize some if-statements
This commit is contained in:
+6
-9
@@ -53,9 +53,9 @@ func printFileEntry(entry string, lastSlash int, charCounter int, colorAlternato
|
|||||||
|
|
||||||
// determine whether to wrap to a new line (+1 is to account for trailing spaces)
|
// determine whether to wrap to a new line (+1 is to account for trailing spaces)
|
||||||
charCounter += len(fileEntryName) + 1
|
charCounter += len(fileEntryName) + 1
|
||||||
if charCounter+(indent*2) >= width {
|
if indentation := indent * 2; charCounter+(indentation) >= width {
|
||||||
charCounter = len(fileEntryName) + 1
|
charCounter = len(fileEntryName) + 1
|
||||||
fmt.Print("\n" + strings.Repeat(" ", indent*2)) // indent each line
|
fmt.Print("\n" + strings.Repeat(" ", indentation)) // indent each line
|
||||||
}
|
}
|
||||||
|
|
||||||
// print fileEntryName to screen
|
// print fileEntryName to screen
|
||||||
@@ -118,9 +118,10 @@ func EntryListGen() {
|
|||||||
colorAlternator = 1
|
colorAlternator = 1
|
||||||
|
|
||||||
// default to assuming this directory will be skipped (unless it is the root)
|
// default to assuming this directory will be skipped (unless it is the root)
|
||||||
skippedDirList[i] = true
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
skippedDirList[i] = false
|
skippedDirList[i] = false
|
||||||
|
} else {
|
||||||
|
skippedDirList[i] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine directory's indentation multiplier based on PathSeparator occurrences
|
// determine directory's indentation multiplier based on PathSeparator occurrences
|
||||||
@@ -128,8 +129,7 @@ func EntryListGen() {
|
|||||||
|
|
||||||
// check if next directory is within the current one
|
// check if next directory is within the current one
|
||||||
if dirListLength > i+1 {
|
if dirListLength > i+1 {
|
||||||
nextDir := dirList[i+1]
|
if nextDir := dirList[i+1]; directory == nextDir[:strings.LastIndex(nextDir, PathSeparator)] {
|
||||||
if directory == nextDir[:strings.LastIndex(nextDir, PathSeparator)] {
|
|
||||||
containsSubdirectory = true
|
containsSubdirectory = true
|
||||||
} else {
|
} else {
|
||||||
containsSubdirectory = false
|
containsSubdirectory = false
|
||||||
@@ -142,11 +142,8 @@ func EntryListGen() {
|
|||||||
containsFiles := false // indicates whether the current directory contains files (entries)
|
containsFiles := false // indicates whether the current directory contains files (entries)
|
||||||
for _, file := range fileList {
|
for _, file := range fileList {
|
||||||
|
|
||||||
// get index of last occurrence of pathSeparator in trimmed entry path (used to split entry's containing directory and entry's name)
|
|
||||||
lastSlash := strings.LastIndex(file, PathSeparator) + 1
|
|
||||||
|
|
||||||
// print the current file if it belongs in the current directory - otherwise, break the loop and move on to the next directory
|
// print the current file if it belongs in the current directory - otherwise, break the loop and move on to the next directory
|
||||||
if file[:lastSlash-1] == directory {
|
if lastSlash := strings.LastIndex(file, PathSeparator) + 1; file[:lastSlash-1] == directory {
|
||||||
|
|
||||||
// print directory header if this is the first run of the loop
|
// print directory header if this is the first run of the loop
|
||||||
if !containsFiles {
|
if !containsFiles {
|
||||||
|
|||||||
Reference in New Issue
Block a user