[OE-core] [PATCH] spp: optimize strip_common_prefix function

Bruce Ashfield bruce.ashfield at gmail.com
Fri Aug 30 03:39:14 UTC 2019


This needs to go to the linux-yocto list.

Cheers,

Bruce

On Thu, Aug 29, 2019 at 10:42 PM Zhaolong Zhang <zhangzl2013 at 126.com> wrote:
>
> 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
>


-- 
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II


More information about the Openembedded-core mailing list