From 47e77aaa2bed7c96e727a3d33cf3fb779212be2f Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 12 Jul 2018 14:07:53 +0200 Subject: merge-kernel-configs: run in O(n log(n)) instead of O(n^2) --- merge-kernel-configs | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/merge-kernel-configs b/merge-kernel-configs index d8d86e3..cf58157 100755 --- a/merge-kernel-configs +++ b/merge-kernel-configs @@ -1,26 +1,32 @@ #!/bin/bash -# merge-kernel-configs $out -# (reads from stdin) +# merge-kernel-configs +# (reads from stdin, writes to stdout) -rm -f "$1" -touch "$1" - -while read -r line; do - variable=$( - printf '%s\n' "${line}" | \ - sed ' - s/^# \(\S\+\) is not set$/\1/ - t - s/=.*$// - t - d - ' - ) - if [ -z "${variable}" ] || \ - grep -q '^\(# \)\?'"${variable}"'[= ]' "$1"; then - continue - fi - printf '%s\n' "${line}" >> \ - "$1" -done +sed ' + s/^# \(\S\+\) is not set$/\1 \0/ + tf + s/^\(\S\+\)=/\1 \0/ + tf + d + :f + = +' | \ + sed ' + N + s/\n/ / + ' | \ + while read -r num variable line; do + printf '%s %s %s\n' \ + "${num}" \ + "$( + printf '%s\n' "${line}" | \ + base64 -w0 + )" \ + "${variable}" + done | \ + sort -k3,3 -k1n,1 -k2,2 | \ + uniq -f2 | \ + sort -k1,1 | \ + cut -d' ' -f2 | \ + parallel --pipe -L1 base64 -d -- cgit v1.2.3-70-g09d2