This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: container<POD> refactoring
On Mon, Sep 20, 2004 at 01:28:00PM -0500, Gabriel Dos Reis wrote:
> Joe Buck <Joe.Buck@synopsys.COM> writes:
>
> | Has anyone done any thinking about adding specializations for avoiding
> | bloat with containers of POD types? For std::vector, it seems that all
> | of the out-of-line functions other than the == and < operators depend
> | only on the size of the POD, and nothing else.
>
> I would say this is something best done at the linker level.
> User-codes may detect -- at program source level -- whether we
> specialize or not.
The linker could resolve cases where the exact same code is generated.
However, relying on that has two limitations:
- While the exact same code will work, the compiler may not generate the
exact same code. Consider vector<int> vs vector<float>. The latter
might generate floating point copies for insertion functions.
- Some opportunities for refactoring are missed. For most of these
functions, the same code could handle PODs of different sizes with
nearly no penalty (the __insert_aux function for a POD of four bytes
and a POD of eight bytes is basically the same; at some point there
is a multiplication by the size).
- Speed penalty (though I don't know if this is significant). If we
can avoid expanding, compiling, and then discarding function bodies
for many STL functions in common cases, there may be a speedup; this
has to weigh against the extra cost of parsing extra specializations,
of course.