speed of mpz_odd_p and lazy allocation

Gabriel Dos Reis gdr at integrable-solutions.net
Mon Aug 20 22:03:25 CEST 2012


On Mon, Aug 20, 2012 at 2:43 PM, Marc Glisse <marc.glisse at inria.fr> wrote:
> On Mon, 20 Aug 2012, Gabriel Dos Reis wrote:
>
>> On Mon, Aug 20, 2012 at 2:24 PM, Marc Glisse <marc.glisse at inria.fr> wrote:
>>>
>>> This is perfectly fine, it is optimization n°2 for the case where the
>>> move
>>> constructor throws, but the move assignment (swap) doesn't. It is unclear
>>> whether this optimization will be implemented by any vendor. If mpz_init
>>> allocates, it remains slow.
>>
>>
>> What would be the basis for a vendor to assume that
>> the elements from the old vector should be assigned
>> as opposed to being copy constructed into the new vector?
>
>
> Are you asking if it is legal to implement reserve() this way (after
> detecting the right constructors/operators)?

No.  Being "legal" does not necessarily mean that it will be done.
For example, it is legal of reserve() to make as many useless
computations as it wants (including useless copies);  that does not
mean that it will be implemented that way.

>  Or how we can guess if this
> "optimization" is really an improvement?


More information about the gmp-devel mailing list