]> Lady’s Gitweb - Shushe/commitdiff
Just manually parse hexadecimal in Awk 0.5.2
authorLady <redacted>
Sat, 3 Feb 2024 23:25:56 +0000 (18:25 -0500)
committerLady <redacted>
Sun, 4 Feb 2024 00:49:30 +0000 (19:49 -0500)
The biggest performance bottleneck in this code was the fact that, for
compatibility reasons, Awk was piping hexadecimal numbers to the shell
in order to parse them. (Macintosh Awk can parse hexadecimal numbers in
`printf`, but G·N·U Awk cannot.)

Because the hexadecimal number is known to be two digits, it’s easy to
just parse it in Awk directly, avoiding the shell pipe and considerably
speeding up the program.

GNUmakefile

index d0989c1277a1cd8b7a0e21b111a27f9b04e214e1..8306fc14333ddb55a71b1ef5bd8f012dd17f4a78 100644 (file)
@@ -216,7 +216,7 @@ override silent := $(if $(VERBOSE),,@)
 override sedesc = $(subst /,[/],$(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1)))))))
 
 # The command to use for percent‐decoding.
-override perdeccmd := $(SED) 's/|/%7C/g;s/[\]/%5C/g;s/%[0-9A-Fa-f]\{2\}/|&|/g' | $(TR) '|' '\n' | $(SED) '/^%[0-9A-Fa-f]\{2\}$$/!s/%/|%25|/' | $(TR) '|' '\n' | $(AWK) '$$0!~/%/{printf "%s",$$0}/%/{sub("%","0x");cmd="$(XARGS) $(PRINTF) \"%04o\"";printf "%s","\\";printf "%s",$$0|cmd;close(cmd)}' | $(XARGS) -0 $(PRINTF) '%b'
+override perdeccmd := $(SED) 's/|/%7C/g;s/[\]/%5C/g;s/%[0-9A-Fa-f]\{2\}/|&|/g' | $(TR) '|' '\n' | $(SED) '/^%[0-9A-Fa-f]\{2\}$$/!s/%/|%25|/' | $(TR) '|' '\n' | $(AWK) '$$0!~/%/{printf "%s",$$0}/%/{d="0123456789ABCDEF";v=substr(toupper($$0),2,2);printf "\\%04o",(index(d,substr(v,1,1))-1)*16+index(d,substr(v,2,1))-1}' | $(XARGS) -0 $(PRINTF) '%b'
 
 # (callable) Percent‐decode the given strings.
 #
This page took 0.032936 seconds and 4 git commands to generate.