autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AS_VAR_APPEND


From: Ralf Wildenhues
Subject: Re: AS_VAR_APPEND
Date: Mon, 20 Oct 2008 22:45:04 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

Hi Eric,

* Eric Blake wrote on Mon, Oct 20, 2008 at 03:20:41PM CEST:
> 
> I'm planning on applying this tomorrow after some more testing, or earlier
> if a review is offered.  This adds AS_VAR_APPEND, which allows linear
> scaling of variable content growth on shells that permit var+=text (with a
> fallback to good old quadratic var=${var}text on shells without the
> extension), then replaces all instances that I could find in the source
> code that were doing an append (although I may have missed some instances
> hidden behind an eval).
> 
> For the record, here is the search I used, to narrow down my search for
> where using this would be relevant:
> git grep '\(^\|[^a-zA-Z_0-9]\)\([a-zA-Z_0-9]\+\)=.\?\$.\?\2' -- '*.m4'

Do you really want to replace all instances where variables are appended
to?  Please note that it will likely slow down the code in most places.
And since this is a pure speedup (as opposed to: correctness) issue, I'd
not use it in places that only append a few times.

The downside of this patch is that it reduces readability of configure a
wee bit, and greppability (searching for 'var=' is quite helpful).
And that it adds a subshell fork to each configure and config.status
invocation (but of course we need to pay that if we use it but once).
:-/

FWIW, when testing this for libtool, I think += was beneficial only when
hundreds of items were appended, viz. when the length of $var was in
several KB at least.

> --- a/doc/autoconf.texi
> +++ b/doc/autoconf.texi
> @@ -12070,6 +12070,15 @@ Polymorphic Variables
>  @end example
>  @end defmac
>  
> address@hidden AS_VAR_APPEND (@var{var}, @var{text})
> address@hidden
> +Emit shell code to append the shell expansion of @var{text} to the end
> +of the current contents of the polymorphic shell variable @var{var}.  A
> +naive implementation of this action scales quadratically,

That is not true.

   var=$var$text

typically scales at most linearly in the size of $var$text; if not, you
should really get a better shell quickly.  Only when used many times in
a row, is there some nonlinear scaling.  What you mean is that appending
should use time linear in the size of the appended text, and amortized
constant wrt. the size of the current contents.

> so when
> +possible, this implementation takes advantage of any shell extensions
> +such as @samp{var+=text} to provide scaling in amortized linear time.
> address@hidden defmac


> +# _AS_VAR_APPEND_PREPARE
> +# ----------------------
> +# Define as_func_append to the optimum definition for the current
> +# shell (bash and zsh provide the += assignment operator to avoid
> +# quadratic append growth).
> +m4_defun([_AS_VAR_APPEND_PREPARE],
> +[AS_FUNCTION_DESCRIBE([as_func_append], [VAR VALUE],
> +[Append the text in VALUE to the end of the definition contained in
> +VAR.  Take advantage of any shell optimizations that allow amortized
> +linear growth, instead of the typical quadratic growth present in
> +naive implementations.])

See above.

Cheers,
Ralf





reply via email to

[Prev in Thread] Current Thread [Next in Thread]