mirror of
https://github.com/gentoo-mirror/gentoo.git
synced 2026-09-23 16:49:10 -07:00
go-module.eclass: inline _go-module_gomod_encode()
The only call site of _go-module_gomod_encode() was using $() in a loop over EGO_SUM. This caused bash to fork() for every loop iteration, which significantly affected the time it takes to "source" an ebuild using EGO_SUM. For example, "pkg pkg source =sys-cluster/k3s-1.23.3_p1" previously took 2.4 seconds. Inlining _go-module_gomod_encode() reduces this to 236 milliseconds. This also adds missing 'local' declarations for some variables. Signed-off-by: Florian Schmaus <flow@gentoo.org> Signed-off-by: William Hubbs <williamh@gentoo.org>
This commit is contained in:
committed by
William Hubbs
parent
a1a4410d13
commit
45e7aecd81
@@ -262,7 +262,22 @@ go-module_set_globals() {
|
||||
continue
|
||||
fi
|
||||
|
||||
_dir=$(_go-module_gomod_encode "${module}")
|
||||
# Encode the name(path) of a Golang module in the format expected by Goproxy.
|
||||
# Upper letters are replaced by their lowercase version with a '!' prefix.
|
||||
# The transformed result of 'module' is stored in the '_dir' variable.
|
||||
#
|
||||
## Python:
|
||||
# return re.sub('([A-Z]{1})', r'!\1', s).lower()
|
||||
## Sed:
|
||||
## This uses GNU Sed extension \l to downcase the match
|
||||
# echo "${module}" |sed 's,[A-Z],!\l&,g'
|
||||
local re _dir lower
|
||||
_dir="${module}"
|
||||
re='(.*)([A-Z])(.*)'
|
||||
while [[ ${_dir} =~ ${re} ]]; do
|
||||
lower='!'"${BASH_REMATCH[2],}"
|
||||
_dir="${BASH_REMATCH[1]}${lower}${BASH_REMATCH[3]}"
|
||||
done
|
||||
|
||||
for _ext in "${exts[@]}" ; do
|
||||
# Relative URI within a GOPROXY for a file
|
||||
@@ -496,33 +511,6 @@ go-module_live_vendor() {
|
||||
popd >& /dev/null || die
|
||||
}
|
||||
|
||||
# @FUNCTION: _go-module_gomod_encode
|
||||
# @DEPRECATED: none
|
||||
# @DESCRIPTION:
|
||||
# Encode the name(path) of a Golang module in the format expected by Goproxy.
|
||||
#
|
||||
# Upper letters are replaced by their lowercase version with a '!' prefix.
|
||||
#
|
||||
_go-module_gomod_encode() {
|
||||
## Python:
|
||||
# return re.sub('([A-Z]{1})', r'!\1', s).lower()
|
||||
|
||||
## Sed:
|
||||
## This uses GNU Sed extension \l to downcase the match
|
||||
#echo "${module}" |sed 's,[A-Z],!\l&,g'
|
||||
#
|
||||
# Bash variant:
|
||||
debug-print-function "${FUNCNAME}" "$@"
|
||||
#local re input lower
|
||||
re='(.*)([A-Z])(.*)'
|
||||
input="${1}"
|
||||
while [[ ${input} =~ ${re} ]]; do
|
||||
lower='!'"${BASH_REMATCH[2],}"
|
||||
input="${BASH_REMATCH[1]}${lower}${BASH_REMATCH[3]}"
|
||||
done
|
||||
echo "${input}"
|
||||
}
|
||||
|
||||
fi
|
||||
|
||||
if [[ ! ${GO_OPTIONAL} ]]; then
|
||||
|
||||
Reference in New Issue
Block a user