From c0d93e4740d8c4d74539024a1bf9a5a7fe15a56c Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Mon, 12 May 2025 16:39:36 +0200 Subject: [PATCH] Do not use huge fish list Using a file is significantly faster. Profiling overview (times in microseconds): - cargo expand: from 4959320 to 4503409 (speedup 1.1) - gettext call pipeline: from 436996 to 13536 (speedup 32.3) - static string pipeline: from 477429 to 404880 (speedup 1.18) --- build_tools/fish_xgettext.fish | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/build_tools/fish_xgettext.fish b/build_tools/fish_xgettext.fish index b844cabcd..98bf072ed 100755 --- a/build_tools/fish_xgettext.fish +++ b/build_tools/fish_xgettext.fish @@ -15,22 +15,25 @@ begin echo "" end >$output_file +set -l tmpfile (mktemp) # This is a gigantic crime. # We use cargo-expand to get all our wgettext invocations. # This might be replaced once we have a tool which properly handles macro expansions. -set -l expanded (cargo expand --lib; for f in fish fish_indent fish_key_reader; cargo expand --bin $f; end) +begin cargo expand --lib; for f in fish fish_indent fish_key_reader; cargo expand --bin $f; end; end >$tmpfile # Extract any gettext call -set -l strs (printf '%s\n' $expanded | grep -A1 wgettext_static_str | +set -l strs (grep -A1 wgettext_static_str <$tmpfile | grep 'widestring::internals::core::primitive::str =' | string match -rg '"(.*)"' | string match -rv '^%ls$|^$' | # escaping difference between gettext and cargo-expand: single-quotes string replace -a "\'" "'") # Extract any constants -set -a strs (string match -rv 'BUILD_VERSION:|PACKAGE_NAME' -- $expanded | +set -a strs (string match -rv 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile | string match -rg 'const [A-Z_]*: &str = "(.*)"' | string replace -a "\'" "'") +rm $tmpfile + # Sort the extracted strings and remove duplicates. # This is optional. set -l strs (string join \n -- $strs | sort -u)