[Asterisk-Dev] ast_strlen_zero or ast_empty_string() ?
Luigi Rizzo
rizzo at icir.org
Wed May 4 11:15:19 MST 2005
just to clarify, i prefer not to use macros or inline functions
because of the potential code bloat, that sometimes (measured!)
makes the code actually slower than using ordinary functions due
to cache pollution.
Unless you are writing the inner part of a very heavily used loop
there is usually no way to notice the extra function call overhead.
This said, macros in some cases may be the only way to go,
and when performance matters inline functions are generally
more readable than macros.
cheers
luigi
On Wed, May 04, 2005 at 08:00:39AM -0700, Kevin P. Fleming wrote:
> Andrew Kohlsmith wrote:
>
> > Why not
> >
> > #define ast_empty_string(x) ( x==NULL || *s == '\0' )
> >
> > ?? Why incur the call overhead or piss around with declaring it inline?
>
> Well, one reason is that if the argument to the macro has side effects,
> they will happen twice. For example:
>
> if (ast_empty_string(array[x++]))
>
> Granted, this is an unusual case, but it's still legitimate. 'static
> inline' declared in a header file is essentially the same as a macro as
> far as code generation/optimization, unless optimization is turned
> completely off.
> _______________________________________________
> Asterisk-Dev mailing list
> Asterisk-Dev at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-dev
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-dev
More information about the asterisk-dev
mailing list