Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Arnout Vandecappelle <arnout@mind.be>
To: buildroot@busybox.net
Subject: [Buildroot] [RFC 1/3] pkg-utils: introduce a make-based LOWERCASE function
Date: Tue, 25 Mar 2014 22:47:04 +0100	[thread overview]
Message-ID: <5331F958.2040400@mind.be> (raw)
In-Reply-To: <1395596582-7062-2-git-send-email-thomas.petazzoni@free-electrons.com>

On 23/03/14 18:43, Thomas Petazzoni wrote:
> Until now, our UPPERCASE function was implemented purely in make for
> performance reasons, but our LOWERCASE function was implemented by
> calling "tr", which was reasonable due to the fact that LOWERCASE was
> rarely used.
> 
> An upcoming change is going to make LOWERCASE used quite a bit more,
> so we turn it into a pure make function.
> 
> Moreover, we want this LOWERCASE function to turn a "_" into a "-" and
> not a ".", so we slightly adjust the existing FROM and TO lists to
> make this possible. This doesn't change the behavior of the UPPERCASE
> macro because both "-" and "." are converted into "_" by this
> function.
> 
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> ---
>  package/pkg-utils.mk | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/package/pkg-utils.mk b/package/pkg-utils.mk
> index 91a1981..8c3e534 100644
> --- a/package/pkg-utils.mk
> +++ b/package/pkg-utils.mk
> @@ -13,7 +13,7 @@
>  # as this macro is used a lot it matters
>  # This works by creating translation character pairs (E.G. a:A b:B)
>  # and then looping though all of them running $(subst from,to,text)
> -[FROM] := a b c d e f g h i j k l m n o p q r s t u v w x y z . -
> +[FROM] := a b c d e f g h i j k l m n o p q r s t u v w x y z - .
>  [TO]   := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ _
>  
>  UPPERCASE = $(strip $(eval __tmp := $1) \
> @@ -23,13 +23,12 @@ UPPERCASE = $(strip $(eval __tmp := $1) \
>  	$(__tmp)))) \
>  	$(__tmp))
>  
> -# LOWERCASE macro -- transforms its arguments to lowercase
> -# The above non-tr implementation is not needed, because LOWERCASE is not
> -# called very often
> -
> -define LOWERCASE
> -$(shell echo $1 | tr '[:upper:]' '[:lower:]')
> -endef
> +LOWERCASE = $(strip $(eval __tmp := $1) \
> +	$(foreach c, $(join $(addsuffix :,$([TO])),$([FROM])), \
> +		$(eval __tmp :=	\
> +		$(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),\
> +	$(__tmp)))) \
> +	$(__tmp))

 I get a further 30-40% speedup with the following definition:


define caseconvert-helper
$(1) = $$(strip \
	$$(eval __tmp := $$(1))\
	$(foreach c, $(2),\
		$$(eval __tmp := $$(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),$$(__tmp))))\
	$$(__tmp))
endef

$(eval $(call caseconvert-helper,UPPERCASE,$(join $(addsuffix :,$([FROM])),$([TO]))))
$(eval $(call caseconvert-helper,LOWERCASE,$(join $(addsuffix :,$([TO])),$([FROM]))))


(this avoids re-evaluating the foreach in every call).


 Regards,
 Arnout

>  
>  #
>  # Manipulation of .config files based on the Kconfig
> 


-- 
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F

  reply	other threads:[~2014-03-25 21:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-23 17:42 [Buildroot] [RFC 0/3] Speeding up the Makefile parsing Thomas Petazzoni
2014-03-23 17:43 ` [Buildroot] [RFC 1/3] pkg-utils: introduce a make-based LOWERCASE function Thomas Petazzoni
2014-03-25 21:47   ` Arnout Vandecappelle [this message]
2014-03-23 17:43 ` [Buildroot] [RFC 2/3] Makefile: include only the package .mk files that are needed Thomas Petazzoni
2014-03-23 17:43 ` [Buildroot] [RFC 3/3] package: add a few needed host options for a few packages Thomas Petazzoni
2014-03-25 22:06   ` Arnout Vandecappelle
2014-03-23 20:38 ` [Buildroot] [RFC 0/3] Speeding up the Makefile parsing Peter Korsgaard
2014-03-23 20:57   ` Thomas Petazzoni
2014-03-25 21:03     ` Arnout Vandecappelle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5331F958.2040400@mind.be \
    --to=arnout@mind.be \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox