From acc93c12198350212241dd88be572da042834792 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 10 May 2019 21:29:07 +0200 Subject: sfeed_opml_export: optimize Tested using 1000 feeds, took about 20s, now 0.02s. The overhead of sed and printf was too high. Now pipe an intermediate TAB format to awk and print it in one stage. --- sfeed_opml_export | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'sfeed_opml_export') diff --git a/sfeed_opml_export b/sfeed_opml_export index 5d88165..82704a6 100755 --- a/sfeed_opml_export +++ b/sfeed_opml_export @@ -22,21 +22,11 @@ loadconfig() { fi } -# escape(s) -escape() { - printf '%s' "$1" | sed -e 's@&@\&@g' -e 's@"@\"@g'\ - -e "s@'@\'@g" -e 's@<@\<@g' -e 's@>@\>@g' -} - # override feeds function to ouput opml XML. # feed(name, feedurl, [basesiteurl], [encoding]) feed() { - name=$(escape "$1") - xmlurl=$(escape "$2") - htmlurl=$(escape "$3") - - printf '\t\n' \ - "${name}" "${name}" "${xmlurl}" "${htmlurl}" + # NOTE: TABs in field values are unsupported, be sane. + echo "$1 $2 $3" } # load config file. @@ -51,9 +41,18 @@ cat < ! -feeds -# wait till all items are processed (concurrently). -wait +feeds | LC_ALL=C awk 'BEGIN { + FS = OFS = "\t"; +} +{ + gsub("&", "\\&"); + gsub("\"", "\\""); + gsub("'"'"'", "\\'"); + gsub("<", "\\<"); + gsub(">", "\\>"); + + print "\t"; +}' cat < -- cgit v1.2.3