1
0
mirror of https://github.com/ryanoasis/nerd-fonts.git synced 2025-01-13 03:03:33 +02:00

generate-css: Speedup by factor of 25

[why]
The script is extremely slow.

[how]
Instead of spawning a new subshell for each glyph (to determine the
codepoint of a char), execute the printf within the current shell.

Before:
./generate-css.sh  25,06s user 33,26s system 101% cpu 57,414 total

After:
./generate-css.sh  1,89s user 0,50s system 102% cpu 2,330 total

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2024-11-26 12:20:07 +01:00 committed by Fini
parent c09f4c09b9
commit b4d1b5bdd1

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Nerd Fonts Version: 3.3.0 # Nerd Fonts Version: 3.3.0
# Script Version: 1.2.1 # Script Version: 1.3.0
# Generates CSS file for the font and cheat sheet code # Generates CSS file for the font and cheat sheet code
# shellcheck disable=SC1091 # Do not pull in the sourced file # shellcheck disable=SC1091 # Do not pull in the sourced file
@ -70,13 +70,11 @@ for var in "${!i@}"; do
# replace _ with - # replace _ with -
glyph_name=${glyph_name/_/-} glyph_name=${glyph_name/_/-}
glyph_char=${!var} glyph_char=${!var}
glyph_code=$(printf "%x" "'$glyph_char'")
#echo "$var=${!var}" #echo "$var=${!var}"
#echo "$glyph_name" #echo "$glyph_name"
#echo "$glyph_char" #echo "$glyph_char"
#echo "$glyph_code"
#printf "%x" "'$glyph_char'" #printf "%x" "'$glyph_char'"
if [[ "$glyph_name" != mdi-* ]]; then if [[ "$glyph_name" != mdi-* ]]; then
@ -84,7 +82,7 @@ for var in "${!i@}"; do
{ {
printf ".nf-%s:before {" "$glyph_name" printf ".nf-%s:before {" "$glyph_name"
printf "\\n" printf "\\n"
printf " content: \"\\%s\";" "$glyph_code" printf " content: \"\\%x\";" "'$glyph_char'"
printf "\\n" printf "\\n"
printf "}" printf "}"
printf "\\n" printf "\\n"
@ -92,18 +90,18 @@ for var in "${!i@}"; do
# generate css min rules # generate css min rules
{ {
printf ".nf-%s:before{content:\"\\%s\"}" "$glyph_name" "$glyph_code" printf ".nf-%s:before{content:\"\\%x\"}" "$glyph_name" "'$glyph_char'"
} >> "$output_css_min_file" } >> "$output_css_min_file"
# generate json entry # generate json entry
{ {
printf ",\"%s\":{\"char\":\"%s\",\"code\":\"%s\"}" "$glyph_name" "$glyph_char" "$glyph_code" printf ",\"%s\":{\"char\":\"%s\",\"code\":\"%x\"}" "$glyph_name" "$glyph_char" "'$glyph_char'"
} >> "$output_json_file" } >> "$output_json_file"
else else
# generate css min rules for removed glyphs # generate css min rules for removed glyphs
{ {
printf ".nfold-%s:before{content:\"\\%s\"}" "$glyph_name" "$glyph_code" printf ".nfold-%s:before{content:\"\\%x\"}" "$glyph_name" "'$glyph_char'"
} >> "$output_css_min_rem_file" } >> "$output_css_min_rem_file"
fi fi
@ -114,7 +112,7 @@ for var in "${!i@}"; do
else else
namespace="nf" namespace="nf"
fi fi
printf " \"%s-%s\": \"%s\",\\n" "$namespace" "$glyph_name" "$glyph_code" printf " \"%s-%s\": \"%x\",\\n" "$namespace" "$glyph_name" "'$glyph_char'"
} >> "$output_cheat_sheet_file" } >> "$output_cheat_sheet_file"
done done