Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache all entries to calculate index #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -6684,6 +6684,16 @@ _list() {
local _max_id
_max_id="$(_index get_max_id "${_list_path}")"

if ! ((_no_id))
then
declare -A _index_map
__i=0
while IFS= read -r line; do
__i=$((++__i))
_index_map[$line]=$__i
done < "${_notebook_path:-}/.index"
fi

# Use code blocks to capture all output for piping to pager.
{
_list_files "${_list_files_options[@]}" || :
Expand Down Expand Up @@ -6839,11 +6849,7 @@ _list() {
_info_line="${_item_info}"
_info_line_color="${_item_info}"
else
local _item_id=
# use `sed` directly instead of `_index get_id` for performance
_item_id="$(
sed -n "/^${__basename:-}$/=" "${_list_path:-}/.index"
)"
local _item_id=${_index_map[${__basename:-}]}

if [[ -n "${_maybe_scope:-}" ]]
then
Expand Down