All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spp: optimize strip_common_prefix function
@ 2019-08-30  2:39 Zhaolong Zhang
  2019-08-30  2:45 ` zhangzl2013
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Zhaolong Zhang @ 2019-08-30  2:39 UTC (permalink / raw)
  To: bruce.ashfield, openembedded-core

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@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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-30  3:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-30  2:39 [PATCH] spp: optimize strip_common_prefix function Zhaolong Zhang
2019-08-30  2:45 ` zhangzl2013
2019-08-30  3:02 ` ✗ patchtest: failure for " Patchwork
2019-08-30  3:39 ` [PATCH] " Bruce Ashfield

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.