Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] Re: (PR#7195) inlining map_pos_to_index
Home

[Freeciv-Dev] Re: (PR#7195) inlining map_pos_to_index

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#7195) inlining map_pos_to_index
From: "Jason Short" <jshort@xxxxxxxxxxxxxx>
Date: Mon, 5 Jan 2004 09:31:08 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7195 >

rwetmore@xxxxxxxxxxxx wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=7195 >
> 
> 
> Since inline functions are always less effective than macros, what is the
> performance *loss* by going from the previous macro form to the inline one.
> What is the justification for making the change from macro to inline given
> all the inherent problems with inline not shared by macros?

The inline function is faster in this case because it takes advantage of 
temporary variables and thus only has to do about two-thirds of the work 
that the macro does.  This is also why it's shorter.

Besides being able to use temp variables, inline functions have other 
advantages:

- Use loops and other complex constructs while retaining a *functional* 
macro.

- Resolve parameters just once (at the start of the function) rather 
than every time they are used in the macro.  This makes things faster 
and avoids potential bugs.

- Better type checking of parameters.

- More readible header files.  Function declarations and implementations 
are separated.

The only drawback is that the optimized code *may* be slower in some 
cases for some compilers.

Personally I would prefer functions (inline or not) in all cases over 
macros.  But I'm not religious about it.

jason




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