speed up comparison of endpoints

This commit is contained in:
Evan Tschannen 2020-05-19 20:41:56 -07:00
parent bf9f24beb5
commit c09a28b0db
2 changed files with 7 additions and 12 deletions

View File

@ -122,10 +122,11 @@ const Endpoint& EndpointMap::insert( NetworkAddressList localAddresses, std::vec
}
UID base = deterministicRandom()->randomUniqueID();
for(int i=0; i<streams.size(); i++) {
for(uint64_t i=0; i<streams.size(); i++) {
int index = adjacentStart+i;
streams[i].first->setEndpoint( Endpoint( localAddresses, UID( (base.first()+(2*i)) | TOKEN_STREAM_FLAG, (base.second()&0xffffffff00000000LL) | index) ) );
data[index].token() = Endpoint::Token( (base.first()+(2*i)) | TOKEN_STREAM_FLAG, (base.second()&0xffffffff00000000LL) | static_cast<uint32_t>(streams[i].second) );
uint64_t first = (base.first()+(i<<32)) | TOKEN_STREAM_FLAG;
streams[i].first->setEndpoint( Endpoint( localAddresses, UID( first, (base.second()&0xffffffff00000000LL) | index) ) );
data[index].token() = Endpoint::Token( first, (base.second()&0xffffffff00000000LL) | static_cast<uint32_t>(streams[i].second) );
data[index].receiver = (NetworkMessageReceiver*) streams[i].first;
}

View File

@ -68,23 +68,17 @@ public:
Endpoint getAdjustedEndpoint( uint32_t index ) {
uint32_t newIndex = token.second();
newIndex += index;
return Endpoint( addresses, UID(token.first()+(2*index), (token.second()&0xffffffff00000000LL) | newIndex) );
return Endpoint( addresses, UID(token.first()+(uint64_t(index)<<32), (token.second()&0xffffffff00000000LL) | newIndex) );
}
bool operator == (Endpoint const& r) const {
return getPrimaryAddress() == r.getPrimaryAddress() && token == r.token;
return token == r.token && getPrimaryAddress() == r.getPrimaryAddress();
}
bool operator != (Endpoint const& r) const {
return !(*this == r);
}
bool operator < (Endpoint const& r) const {
const NetworkAddress& left = getPrimaryAddress();
const NetworkAddress& right = r.getPrimaryAddress();
if (left != right)
return left < right;
else
return token < r.token;
return token < r.token || (token == r.token && getPrimaryAddress() < r.getPrimaryAddress());
}
template <class Ar>