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
22
mo
22
mo
@ -115,6 +115,8 @@ mo() (
|
|||||||
moDoubleHyphens=false
|
moDoubleHyphens=false
|
||||||
MO_OPEN_DELIMITER_DEFAULT="{{"
|
MO_OPEN_DELIMITER_DEFAULT="{{"
|
||||||
MO_CLOSE_DELIMITER_DEFAULT="}}"
|
MO_CLOSE_DELIMITER_DEFAULT="}}"
|
||||||
|
MO_FUNCTION_CACHE_HIT=()
|
||||||
|
MO_FUNCTION_CACHE_MISS=()
|
||||||
|
|
||||||
if [[ $# -gt 0 ]]; then
|
if [[ $# -gt 0 ]]; then
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
@ -911,9 +913,27 @@ mo::parseValue() {
|
|||||||
#
|
#
|
||||||
# Returns 0 if the name is a function, 1 otherwise.
|
# Returns 0 if the name is a function, 1 otherwise.
|
||||||
mo::isFunction() {
|
mo::isFunction() {
|
||||||
if declare -F "$1" &> /dev/null; then
|
local moFunctionName
|
||||||
|
|
||||||
|
for moFunctionName in "${MO_FUNCTION_CACHE_HIT[@]}"; do
|
||||||
|
if [[ "$moFunctionName" == "$1" ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
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
|
return 1
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user