Boost logo

Boost :

Subject: Re: [boost] [uuids] On boost::uuids::uuid operator == performance.
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-04-16 05:59:26


On 16/04/12 01:10, Michael Kochetkov wrote:

> boost uses the following comparison operator:
> inline bool operator==(uuid const& lhs, uuid const& rhs) /* throw() */
> {
> return std::equal(lhs.begin(), lhs.end(), rhs.begin());
> }
>
> which end up with the following code:
> lea edx, DWORD PTR _id2$[esp+92]
> lea ecx, DWORD PTR _id1$[esp+108]
> lea eax, DWORD PTR _id1$[esp+92]
> call ?_Equal_at_std@@YA_NPBE00_at_Z ; std::_Equal

A good implementation of std::equal would call memcmp here, which would
already be optimized.

That doesn't seem to be the case.

Can you try replacing this by memcmp(lhs.begin(), rhs.begin(), lhs.size()) ?

> inline
> bool comp(const boost::uuids::uuid& l, const boost::uuids::uuid& r) {
> return *reinterpret_cast<const uint32_t*>(l.data) ==
> *reinterpret_cast<const uint32_t*>(r.data)
> && *reinterpret_cast<const uint32_t*>(l.data+4) ==
> *reinterpret_cast<const uint32_t*>(r.data+4)
> && *reinterpret_cast<const uint32_t*>(l.data+8) ==
> *reinterpret_cast<const uint32_t*>(r.data+8)
> && *reinterpret_cast<const uint32_t*>(l.data+12) ==
> *reinterpret_cast<const uint32_t*>(r.data+12);
> }

This code is specific to 32-bit architectures and also breaks the
strict-aliasing rule.


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