Boost logo

Boost :

Subject: Re: [boost] BOOST_FORCE_INLINE
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2011-10-10 13:37:51


El 10/10/2011 10:47, Thorsten Ottosen escribió:

> After running this, I had a great overview over which functions took up
> most of the time, and which functions that were called a lot (say, many
> million times). Usually,
> the compiler will not inline a large function because the saved time is
> neglible and more code is generated. However, the compiler can usually
> not know that a large function often returns quickly where large parts
> of the code of the function is only used sometimes.

Sometimes is useful to split the function into two functions, one with
the fast path and another with a call to a non-inlineable functions:

void push_back(const T &t) //<- inlineable
{
   if(m_capacity > m_size){
      new (m_buffer+m_size) T(t);
      ++m_size;
   }
   else{
      expand_and_insert_back(t); //<- non-inlineable big function
   }
}

Of course this does not guarantee push_back will be inlined... so I'd
apply BOOST_FORCE_INLINE to push_back ;-)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk