IPC: Use <algorithm> helpers for comparing arrays
Use std::equal and std::lexicographical_compare for comparing nonce arrays, rather than manual iteration and comparison. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1451173002 Cr-Commit-Position: refs/heads/master@{#360115}
This commit is contained in:
@ -7,6 +7,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "ipc/ipc_export.h"
|
||||
#include "ipc/ipc_message_attachment.h"
|
||||
@ -37,21 +39,12 @@ class IPC_EXPORT BrokerableAttachment : public MessageAttachment {
|
||||
void SerializeToBuffer(char* start_address, size_t size);
|
||||
|
||||
bool operator==(const AttachmentId& rhs) const {
|
||||
for (size_t i = 0; i < kNonceSize; ++i) {
|
||||
if (nonce[i] != rhs.nonce[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return std::equal(nonce, nonce + kNonceSize, rhs.nonce);
|
||||
}
|
||||
|
||||
bool operator<(const AttachmentId& rhs) const {
|
||||
for (size_t i = 0; i < kNonceSize; ++i) {
|
||||
if (nonce[i] < rhs.nonce[i])
|
||||
return true;
|
||||
if (nonce[i] > rhs.nonce[i])
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return std::lexicographical_compare(nonce, nonce + kNonceSize, rhs.nonce,
|
||||
rhs.nonce + kNonceSize);
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user