mirror of
https://github.com/tw93/Mole.git
synced 2026-02-10 18:24:14 +00:00
refactor: simplify with slices.Clone
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -27,8 +28,8 @@ var (
|
|||||||
func snapshotFromModel(m model) historyEntry {
|
func snapshotFromModel(m model) historyEntry {
|
||||||
return historyEntry{
|
return historyEntry{
|
||||||
Path: m.path,
|
Path: m.path,
|
||||||
Entries: cloneDirEntries(m.entries),
|
Entries: slices.Clone(m.entries),
|
||||||
LargeFiles: cloneFileEntries(m.largeFiles),
|
LargeFiles: slices.Clone(m.largeFiles),
|
||||||
TotalSize: m.totalSize,
|
TotalSize: m.totalSize,
|
||||||
TotalFiles: m.totalFiles,
|
TotalFiles: m.totalFiles,
|
||||||
Selected: m.selected,
|
Selected: m.selected,
|
||||||
@@ -45,24 +46,6 @@ func cacheSnapshot(m model) historyEntry {
|
|||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneDirEntries(entries []dirEntry) []dirEntry {
|
|
||||||
if len(entries) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
copied := make([]dirEntry, len(entries))
|
|
||||||
copy(copied, entries) //nolint:all
|
|
||||||
return copied
|
|
||||||
}
|
|
||||||
|
|
||||||
func cloneFileEntries(files []fileEntry) []fileEntry {
|
|
||||||
if len(files) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
copied := make([]fileEntry, len(files))
|
|
||||||
copy(copied, files) //nolint:all
|
|
||||||
return copied
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureOverviewSnapshotCacheLocked() error {
|
func ensureOverviewSnapshotCacheLocked() error {
|
||||||
if overviewSnapshotLoaded {
|
if overviewSnapshotLoaded {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -982,8 +983,8 @@ func (m model) enterSelectedDir() (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cached, ok := m.cache[m.path]; ok && !cached.Dirty {
|
if cached, ok := m.cache[m.path]; ok && !cached.Dirty {
|
||||||
m.entries = cloneDirEntries(cached.Entries)
|
m.entries = slices.Clone(cached.Entries)
|
||||||
m.largeFiles = cloneFileEntries(cached.LargeFiles)
|
m.largeFiles = slices.Clone(cached.LargeFiles)
|
||||||
m.totalSize = cached.TotalSize
|
m.totalSize = cached.TotalSize
|
||||||
m.totalFiles = cached.TotalFiles
|
m.totalFiles = cached.TotalFiles
|
||||||
m.selected = cached.Selected
|
m.selected = cached.Selected
|
||||||
|
|||||||
Reference in New Issue
Block a user