empty function optimizations
Ken Clark
ken@gesn.com
Tue Jul 11 15:59:00 GMT 2000
> Well, just take one of your examples. Please post a class template
> with some method, where the template is instantiated with two
> different types, but the method "ought to" be identical. My guess is
> it won't be possible to merge them just by looking at the machine code.
>
> Regards,
> Martin
Trivial. Just invent a array template with the number of elements as the
first member. The size() function is going to look the same regardless of
the contents of the array. I guess you aren't going to be impressed by that
though.
Attached is a STL example that calls the list::operator=() function. Take a
look at
"erase__t4list2Z3fooZt24__default_alloc_template2b1i0Gt15__list_iterator3Z3f
ooZR3fooZP3fooT1:" and its baz counterpart. They are line for line
identical.
The point being, templates very often operate on pointers to objects (or
otherwise indirectly), not the objects themselves. That is nice for type
safety, but it doesn't change the asm on machines with a sane pointer
implementation. In my particular app the templates are for database access;
it has similar properties.
Ken
-------------- next part --------------
A non-text attachment was scrubbed...
Name: duplicate.cpp
Type: text/x-c++
Size: 206 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20000711/1806ce43/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: duplicate.s
Type: text/x-asm
Size: 45425 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20000711/1806ce43/attachment-0001.bin>
More information about the Gcc
mailing list