[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] [PATCH 2/2] patches: Optimize the multiple files case
From: |
Jean Delvare |
Subject: |
[Quilt-dev] [PATCH 2/2] patches: Optimize the multiple files case |
Date: |
Sun, 09 Feb 2014 16:02:08 +0100 |
I didn't put too many thoughts when adding support for multiple files
to the "patches" command. The nested loop approach turns out to be
very inefficient for unapplied patches.
Get rid of the innermost loop by building a single pattern matching
all filenames at once. That way, performance no longer depends on the
number of files (as far as unapplied patches are concerned.)
---
quilt/patches.in | 27 ++++++++++++++-------------
quilt/scripts/patchfns.in | 13 +++++++++++++
2 files changed, 27 insertions(+), 13 deletions(-)
--- a/quilt/patches.in
+++ b/quilt/patches.in
@@ -88,7 +88,7 @@ scan_unapplied()
{
local color=$1 prefix=$2 strip
shift 2
- local patch file match
+ local patch file
local -a files_bre
# Quote each file name only once
@@ -97,23 +97,24 @@ scan_unapplied()
address@hidden"$(quote_bre "$file")"
done
+ # If there is more than one file, "or" them all in a single pattern
+ if [ address@hidden -eq 1 ]
+ then
+ file="^${files_bre[0]}\$"
+ else
+ file="^\\($(array_join "\\|" address@hidden)\\)\$"
+ fi
+
for patch in "$@"
do
strip=$(patch_strip_level $patch)
[ "$strip" = ab ] && strip=1
- match=
- for file in "address@hidden"
- do
- if touched_by_patch $strip $patch \
- | grep -q "^$file\$"
- then
- match=1
- break
- fi
- done
-
- [ -z "$match" ] || echo "$color$prefix$(print_patch
$patch)$color_clear"
+ if touched_by_patch $strip "$patch" \
+ | grep -q "$file"
+ then
+ echo "$color$prefix$(print_patch $patch)$color_clear"
+ fi
done
}
--- a/quilt/scripts/patchfns.in
+++ b/quilt/scripts/patchfns.in
@@ -76,6 +76,19 @@ trap run_exit_handlers EXIT
# ========================================================
+# Join multiple stings using the given separator.
+array_join()
+{
+ local sep=$1 first=$2
+ shift 2
+ printf "%s" "$first"
+ while [ -n "$1" ]
+ do
+ printf "%s%s" "$sep" "$1"
+ shift
+ done
+}
+
# Quote a string for use in a basic regular expression.
quote_bre()
{
--
Jean Delvare
Suse L3 Support