Dont store abspath on each result

Optimisation as abspath is calculated in hot path. Instead calculate on
demand.
This commit is contained in:
Kovid Goyal
2025-06-26 19:21:04 +05:30
parent 4256fa5418
commit 17c84383f7
3 changed files with 9 additions and 9 deletions

View File

@@ -230,7 +230,7 @@ func (h *Handler) current_abspath() string {
matches, _ := h.get_results()
if len(matches) > 0 {
if idx := h.state.CurrentIndex(); idx < len(matches) {
return matches[idx].abspath
return filepath.Join(h.state.CurrentDir(), matches[idx].text)
}
}
return ""

View File

@@ -123,10 +123,11 @@ func icon_for(path string, x os.FileMode) string {
}
func (h *Handler) draw_column_of_matches(matches ResultsType, current_idx int, x, available_width int) {
root_dir := h.state.CurrentDir()
for i, m := range matches {
h.lp.QueueWriteString("\r")
h.lp.MoveCursorHorizontally(x)
icon := icon_for(m.abspath, m.ftype)
icon := icon_for(filepath.Join(root_dir, m.text), m.ftype)
text := m.text
add_ellipsis := false
if wcswidth.Stringwidth(text) > available_width-3 {

View File

@@ -29,10 +29,10 @@ func (c CombinedScore) String() string {
}
type ResultItem struct {
text, abspath string
ftype fs.FileMode
positions []int // may be nil
score CombinedScore
text string
ftype fs.FileMode
positions []int // may be nil
score CombinedScore
}
type ResultsType []*ResultItem
@@ -46,7 +46,7 @@ func (r ResultItem) IsMatching() bool {
}
func (r ResultItem) String() string {
return fmt.Sprintf("{text: %#v, abspath: %#v, %s, positions: %#v}", r.text, r.abspath, r.score, r.positions)
return fmt.Sprintf("{text: %#v, %s, positions: %#v}", r.text, r.score, r.positions)
}
func (r *ResultItem) sorted_positions() []int {
@@ -261,7 +261,6 @@ func (fss *FileSystemScanner) worker() {
new_items := ns[len(ns):new_sz]
for i, e := range sortable {
new_items[i].ftype = e.ftype
new_items[i].abspath = dir + e.name
new_items[i].text = base + e.name
new_items[i].score.Set_index(idx)
idx++
@@ -280,8 +279,8 @@ func (fss *FileSystemScanner) worker() {
dir = ""
for pos < len(fss.results) && dir == "" {
if fss.results[pos].ftype&fs.ModeDir != 0 {
dir = fss.results[pos].abspath + string(os.PathSeparator)
base = fss.results[pos].text + string(os.PathSeparator)
dir = root_dir + string(os.PathSeparator) + base
}
pos++
}