All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] pkg-utils: describe the case conversion macros in more detail.
@ 2014-10-14  9:23 Arnout Vandecappelle
  2014-10-14 14:45 ` Yann E. MORIN
  2014-10-16 17:04 ` Thomas Petazzoni
  0 siblings, 2 replies; 3+ messages in thread
From: Arnout Vandecappelle @ 2014-10-14  9:23 UTC (permalink / raw)
  To: buildroot

After the refactoring of the case conversion macros in dd5e620ac, the
macro became even harder to understand. Improve this explanation a
little so future generations can make sense of what we're doing here.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Cc: Thomas De Schampheleire <patrickdepinguin@gmail.com>
---
Very old patch that I forgot to push

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
---
 package/pkg-utils.mk | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/package/pkg-utils.mk b/package/pkg-utils.mk
index ce39197..7eddc47 100644
--- a/package/pkg-utils.mk
+++ b/package/pkg-utils.mk
@@ -5,14 +5,24 @@
 #
 ################################################################################
 
-# UPPERCASE Macro -- transform its argument to uppercase and replace dots and
-# hyphens to underscores
-
-# Heavily inspired by the up macro from gmsl (http://gmsl.sf.net)
-# This is approx 5 times faster than forking a shell and tr, and
-# 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)
+# Case conversion macros. This is inspired by the 'up' macro from gmsl
+# (http://gmsl.sf.net). It is optimised very heavily because these macros
+# are used a lot. It is about 5 times faster than forking a shell and tr.
+#
+# The caseconvert-helper creates a definition of the case conversion macro.
+# After expansion by the outer $(eval ), the UPPERCASE macro is defined as:
+# $(strip $(eval __tmp := $(1))  $(eval __tmp := $(subst a,A,$(__tmp))) ... )
+# In other words, every letter is substituted one by one.
+#
+# The caseconvert-helper allows us to create this definition out of the
+# [FROM] and [TO] lists, so we don't need to write down every substition
+# manually. The uses of $ and $$ quoting are chosen in order to do as
+# much expansion as possible up-front.
+#
+# Note that it would be possible to conceive a slightly more optimal
+# implementation that avoids the use of __tmp, but that would be even
+# more unreadable and is not worth the effort.
+
 [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 _ _
 
-- 
2.1.1

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

* [Buildroot] [PATCH] pkg-utils: describe the case conversion macros in more detail.
  2014-10-14  9:23 [Buildroot] [PATCH] pkg-utils: describe the case conversion macros in more detail Arnout Vandecappelle
@ 2014-10-14 14:45 ` Yann E. MORIN
  2014-10-16 17:04 ` Thomas Petazzoni
  1 sibling, 0 replies; 3+ messages in thread
From: Yann E. MORIN @ 2014-10-14 14:45 UTC (permalink / raw)
  To: buildroot

Arnout, All,

On 2014-10-14 11:23 +0200, Arnout Vandecappelle (Essensium/Mind) spake thusly:
> After the refactoring of the case conversion macros in dd5e620ac, the
> macro became even harder to understand. Improve this explanation a
> little so future generations can make sense of what we're doing here.
> 
> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
> Cc: Thomas De Schampheleire <patrickdepinguin@gmail.com>

Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

Regards,
Yann E. MORIN.

> ---
> Very old patch that I forgot to push
> 
> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
> ---
>  package/pkg-utils.mk | 26 ++++++++++++++++++--------
>  1 file changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/package/pkg-utils.mk b/package/pkg-utils.mk
> index ce39197..7eddc47 100644
> --- a/package/pkg-utils.mk
> +++ b/package/pkg-utils.mk
> @@ -5,14 +5,24 @@
>  #
>  ################################################################################
>  
> -# UPPERCASE Macro -- transform its argument to uppercase and replace dots and
> -# hyphens to underscores
> -
> -# Heavily inspired by the up macro from gmsl (http://gmsl.sf.net)
> -# This is approx 5 times faster than forking a shell and tr, and
> -# 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)
> +# Case conversion macros. This is inspired by the 'up' macro from gmsl
> +# (http://gmsl.sf.net). It is optimised very heavily because these macros
> +# are used a lot. It is about 5 times faster than forking a shell and tr.
> +#
> +# The caseconvert-helper creates a definition of the case conversion macro.
> +# After expansion by the outer $(eval ), the UPPERCASE macro is defined as:
> +# $(strip $(eval __tmp := $(1))  $(eval __tmp := $(subst a,A,$(__tmp))) ... )
> +# In other words, every letter is substituted one by one.
> +#
> +# The caseconvert-helper allows us to create this definition out of the
> +# [FROM] and [TO] lists, so we don't need to write down every substition
> +# manually. The uses of $ and $$ quoting are chosen in order to do as
> +# much expansion as possible up-front.
> +#
> +# Note that it would be possible to conceive a slightly more optimal
> +# implementation that avoids the use of __tmp, but that would be even
> +# more unreadable and is not worth the effort.
> +
>  [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 _ _
>  
> -- 
> 2.1.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

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

* [Buildroot] [PATCH] pkg-utils: describe the case conversion macros in more detail.
  2014-10-14  9:23 [Buildroot] [PATCH] pkg-utils: describe the case conversion macros in more detail Arnout Vandecappelle
  2014-10-14 14:45 ` Yann E. MORIN
@ 2014-10-16 17:04 ` Thomas Petazzoni
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Petazzoni @ 2014-10-16 17:04 UTC (permalink / raw)
  To: buildroot

Dear Arnout Vandecappelle (Essensium/Mind),

On Tue, 14 Oct 2014 11:23:47 +0200, Arnout Vandecappelle
(Essensium/Mind) wrote:
> After the refactoring of the case conversion macros in dd5e620ac, the
> macro became even harder to understand. Improve this explanation a
> little so future generations can make sense of what we're doing here.
> 
> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
> Cc: Thomas De Schampheleire <patrickdepinguin@gmail.com>

Applied, thanks.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

end of thread, other threads:[~2014-10-16 17:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-14  9:23 [Buildroot] [PATCH] pkg-utils: describe the case conversion macros in more detail Arnout Vandecappelle
2014-10-14 14:45 ` Yann E. MORIN
2014-10-16 17:04 ` Thomas Petazzoni

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.