[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] [PATCH 2/2 v2] patches: Optimize the multiple files case
From: |
Jean Delvare |
Subject: |
[Quilt-dev] [PATCH 2/2 v2] patches: Optimize the multiple files case |
Date: |
Thu, 13 Feb 2014 09:23:37 +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.)
---
Changes since v1:
* Dropped the optimized path for the single file case. The performance
gain doesn't justify having separate code paths.
* Optimized the array_join helper function.
quilt/patches.in | 22 +++++++++-------------
quilt/scripts/patchfns.in | 14 ++++++++++++++
2 files changed, 23 insertions(+), 13 deletions(-)
--- quilt.orig/quilt/patches.in
+++ quilt/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,19 @@ scan_unapplied()
address@hidden(quote_bre "$file")
done
+ # "Or" all files in a single pattern
+ file=\\\($(array_join \\\| "address@hidden")\\\)
+
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
}
--- quilt.orig/quilt/scripts/patchfns.in
+++ quilt/quilt/scripts/patchfns.in
@@ -76,6 +76,20 @@ trap run_exit_handlers EXIT
# ========================================================
+# Join multiple stings using the given separator.
+array_join()
+{
+ local sep=$1 str=$2
+ shift 2
+
+ printf %s "$str"
+
+ for str in "$@"
+ do
+ printf %s%s "$sep" "$str"
+ done
+}
+
# Quote a string for use in a basic regular expression.
quote_bre()
{
--
Jean Delvare
Suse L3 Support