inlining and squid-3

From: Robert Collins <robertc@dont-contact.us>
Date: 30 Oct 2002 23:05:23 +1100

We will likely want to inline many of the trivial methods in squid-3
objects.

Does extern_inline exist for all C++ compilers? I've a suggestion for
inlining that doesn't use extern_inline, but can be trivially modified
to do so if desired:

Firstly, this is aimed at allowing development to use non inlined code
for speeding up the devel cycle, but to switch that over to explicitly
inlined when building distribution binaries. So per-module inlining
isn't needed for this approach. It can be incrementally brought in by an
extra level of control (if (global inlining) define (local inlining)) if
desired.

Approach:
Define two macros for the CXX and C flags (I'll do up configure magic
for this if we agree on the approach):
 -D_SQUID_INLINE_=inline -D_USE_INLINE_
this enables inlining.
We define
 -D_SQUID_INLINE_=
if we are not inlining.

Then, in class definitions, we can mark candidate inlined methods
thusly:
class Foo {
public:
  _SQUID_INLINE_ void someMethod();
};

Now, we create a new file:
Foo.cci (cc inline)
which complements Foo.cc and Foo.h and includes the inlined methods.

At the end of Foo.cc we do:
#ifndef _USE_INLINE_
#include "Foo.cci"
#endif

At the end of Foo.h we do:
#ifdef _USE_INLINE_
#include "Foo.cci"
#endif

within Foo.cci, method implementations are done as normal:
void
Foo:somemethod()
{
}

This allows us to:
* Code methods that may be inlined once, without maintaining two copies.
* Switch easily between inlined and non inlined code bases for
production (inlined) and development (non inlined)

What do you think?

Rob

On Thu, 2002-10-03 at 17:08, Henrik Nordstrom wrote:
> On Wednesday 02 October 2002 23.32, Robert Collins wrote:
>
> > If the code is in a header and can inline, gcc doesn't care whether
> > it will be part of a library or not. (This goes for gcc and g++).
>
>
> Guideline on how to use inline in a manner that works for all/most
> compilers
>
>
> Any inlined functions in header files should be declared using
>
> #ifndef MODULEID_INLINE
> #define MODULEID_INLINE extern_inline
> #endif
>
> MODULEID_INLINE function(...)
> {
> ...
> }
>
> Local functions within the same source file using
> static inline function(...)
> {
> }
>
>
> For each "extern inline" there must be one object file where the
> function is declared without extern
>
> #define MODULEID_INLINE inline
> or alternatively
> #define MODULEID_INLINE
>
> before the #include ...
>
>
> Regards
> Henrik

Received on Wed Oct 30 2002 - 05:05:27 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:17:02 MST