commit acc93c12198350212241dd88be572da042834792
parent 51c35cf03bc6b30b3a8fec6091e5d9eba422f62e
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 10 May 2019 21:29:07 +0200
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.
Diffstat:
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git 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<outline title="%s" text="%s" xmlUrl="%s" htmlUrl="%s"/>\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 <<!
<body>
!
-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<outline title=\"" $1 "\" text=\""$1"\" xmlUrl=\""$2"\" htmlUrl=\""$3"\"/>";
+}'
cat <<!
</body>