mirror of
https://github.com/tests-always-included/mo.git
synced 2024-12-18 16:27:52 +00:00
Caching function name lookups
Faster than dumping functions each time. Related to #73.
This commit is contained in:
parent
26ca5059d8
commit
5db34e55d3
20
mo
20
mo
@ -115,6 +115,8 @@ mo() (
|
||||
moDoubleHyphens=false
|
||||
MO_OPEN_DELIMITER_DEFAULT="{{"
|
||||
MO_CLOSE_DELIMITER_DEFAULT="}}"
|
||||
MO_FUNCTION_CACHE_HIT=()
|
||||
MO_FUNCTION_CACHE_MISS=()
|
||||
|
||||
if [[ $# -gt 0 ]]; then
|
||||
for arg in "$@"; do
|
||||
@ -911,10 +913,28 @@ mo::parseValue() {
|
||||
#
|
||||
# Returns 0 if the name is a function, 1 otherwise.
|
||||
mo::isFunction() {
|
||||
local moFunctionName
|
||||
|
||||
for moFunctionName in "${MO_FUNCTION_CACHE_HIT[@]}"; do
|
||||
if [[ "$moFunctionName" == "$1" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
for moFunctionName in "${MO_FUNCTION_CACHE_MISS[@]}"; do
|
||||
if [[ "$moFunctionName" == "$1" ]]; then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
if declare -F "$1" &> /dev/null; then
|
||||
MO_FUNCTION_CACHE_HIT=( ${MO_FUNCTION_CACHE_HIT[@]+"${MO_FUNCTION_CACHE_HIT[@]}"} "$1" )
|
||||
|
||||
return 0
|
||||
fi
|
||||
|
||||
MO_FUNCTION_CACHE_MISS=( ${MO_FUNCTION_CACHE_MISS[@]+"${MO_FUNCTION_CACHE_MISS[@]}"} "$1" )
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user