[OE-core] [PATCH] spp: optimize strip_common_prefix function
Zhaolong Zhang
zhangzl2013 at 126.com
Fri Aug 30 02:39:23 UTC 2019
strip_common_prefix() is the hot path that executes on every input file.
This patch sorts and uniqs the $include_paths by length descreasingly.
And with the sorted $include_paths, the for-loop inside strip_common_prefix
can break earlier, thus kernel_metadata task can be sped up by multiple times.
Signed-off-by: Zhaolong Zhang <zhangzl2013 at 126.com>
---
tools/spp | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tools/spp b/tools/spp
index 1150ff3..cba52bb 100755
--- a/tools/spp
+++ b/tools/spp
@@ -125,6 +125,7 @@ strip_common_prefix()
if [ $this_len -lt $out_len ]; then
relocated_name=$t
out_len=$this_len
+ break
fi
# add a trailing slash to get corner cases where one may
# have been added or not dropped
@@ -133,6 +134,7 @@ strip_common_prefix()
if [ $this_len -lt $out_len ]; then
relocated_name=$t
out_len=$this_len
+ break
fi
done
@@ -297,6 +299,16 @@ infiles=$@
processed_files=""
+# this function also removes duplicated lines by `sort -u`
+sort_by_len_dec()
+{
+ for i in $@; do
+ echo $i
+ done | sort -u | awk '{ print length($0) " " $0; }' | sort -nr | cut -d ' ' -f 2-
+}
+
+include_paths=$(sort_by_len_dec $include_paths)
+
##
## create variables for use in scripts
##
--
1.9.1
More information about the Openembedded-core
mailing list