Skip to content

Commit

Permalink
util (ble/util/assign-array): improve performace in bash-3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Mar 10, 2019
1 parent 8e4180c commit ae176b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
14 changes: 14 additions & 0 deletions memo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3027,6 +3027,20 @@ bash_tips

2019-03-10

* bash-3.2 以下で sabbrev が動いていない [#D0985]
正規表現? と思ったがそもそも core-complete.sh が読み込まれていない。
ble/complete/sabbrev/expand を autoload に追加しておく事にした。
また、物凄く遅いが一応動いている様子である。

然し、この遅さは何だろう。滅茶苦茶遅い…。
もしかすると全ページを構築している?
と思ったが次のページに行こうとするとやはり時間がかかるので、
恐らく本当に動作が遅いという事なのだろう…。

調べたら ble/util/assign-array に滅茶苦茶時間がかかっていた。
変な split-lines のルーチンよりも while builtin read -r line の方が速いのだった。
2m22s から 0.05s にまで短くなった。約 1000 行のファイルである。

* ble/util/msleep の usleep を使う実装に於いて警告が表示されている [#D0984]
deprecated だそうだ。取り敢えず &>/dev/null で警告を殺す。

Expand Down
16 changes: 10 additions & 6 deletions src/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -751,12 +751,16 @@ if ((_ble_bash>=40000)); then
}
else
function ble/util/assign-array {
ble/util/assign "$@"
if [[ ${!1} ]]; then
ble/string#split-lines "$1" "${!1%$'\n'}"
else
eval "$1=()"
fi
local _ble_local_tmp=$_ble_util_assign_base.$((_ble_util_assign_level++))
builtin eval "$2" >| "$_ble_local_tmp"
local _ble_local_ret=$?
((_ble_util_assign_level--))
local _ble_local_i=0 _ble_local_val _ble_local_arr; _ble_local_arr=()
while builtin read -r _ble_local_val || [[ $_ble_local_val ]]; do
_ble_local_arr[_ble_local_i++]=$_ble_local_val
done < "$_ble_local_tmp"
builtin eval "$1=(\"\${_ble_local_arr[@]}\")"
return "$_ble_local_ret"
}
fi

Expand Down

0 comments on commit ae176b2

Please sign in to comment.