mirror of
https://github.com/ceph/ceph
synced 2024-12-28 22:43:29 +00:00
Merge pull request #34292 from cbodley/wip-bufferlist-comparison
bufferlist: use iterators for comparison operators Reviewed-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
commit
d9ca5e5d7b
@ -1230,44 +1230,40 @@ inline namespace v15_2_0 {
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator>(const bufferlist& l, const bufferlist& r) {
|
||||
for (unsigned p = 0; ; p++) {
|
||||
if (l.length() > p && r.length() == p) return true;
|
||||
if (l.length() == p) return false;
|
||||
if (l[p] > r[p]) return true;
|
||||
if (l[p] < r[p]) return false;
|
||||
}
|
||||
}
|
||||
inline bool operator>=(const bufferlist& l, const bufferlist& r) {
|
||||
for (unsigned p = 0; ; p++) {
|
||||
if (l.length() > p && r.length() == p) return true;
|
||||
if (r.length() == p && l.length() == p) return true;
|
||||
if (l.length() == p && r.length() > p) return false;
|
||||
if (l[p] > r[p]) return true;
|
||||
if (l[p] < r[p]) return false;
|
||||
}
|
||||
inline bool operator==(const bufferlist &lhs, const bufferlist &rhs) {
|
||||
if (lhs.length() != rhs.length())
|
||||
return false;
|
||||
return std::equal(lhs.begin(), lhs.end(), rhs.begin());
|
||||
}
|
||||
|
||||
inline bool operator==(const bufferlist &l, const bufferlist &r) {
|
||||
if (l.length() != r.length())
|
||||
return false;
|
||||
for (unsigned p = 0; p < l.length(); p++) {
|
||||
if (l[p] != r[p])
|
||||
return false;
|
||||
inline bool operator<(const bufferlist& lhs, const bufferlist& rhs) {
|
||||
auto l = lhs.begin(), r = rhs.begin();
|
||||
for (; l != lhs.end() && r != rhs.end(); ++l, ++r) {
|
||||
if (*l < *r) return true;
|
||||
if (*l > *r) return false;
|
||||
}
|
||||
return true;
|
||||
return (l == lhs.end()) && (r != rhs.end()); // lhs.length() < rhs.length()
|
||||
}
|
||||
|
||||
inline bool operator<=(const bufferlist& lhs, const bufferlist& rhs) {
|
||||
auto l = lhs.begin(), r = rhs.begin();
|
||||
for (; l != lhs.end() && r != rhs.end(); ++l, ++r) {
|
||||
if (*l < *r) return true;
|
||||
if (*l > *r) return false;
|
||||
}
|
||||
return l == lhs.end(); // lhs.length() <= rhs.length()
|
||||
}
|
||||
|
||||
inline bool operator!=(const bufferlist &l, const bufferlist &r) {
|
||||
return !(l == r);
|
||||
}
|
||||
inline bool operator<(const bufferlist& l, const bufferlist& r) {
|
||||
return r > l;
|
||||
inline bool operator>(const bufferlist& lhs, const bufferlist& rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
inline bool operator<=(const bufferlist& l, const bufferlist& r) {
|
||||
return r >= l;
|
||||
inline bool operator>=(const bufferlist& lhs, const bufferlist& rhs) {
|
||||
return rhs <= lhs;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const buffer::ptr& bp);
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const buffer::raw &r);
|
||||
|
@ -2540,8 +2540,9 @@ TEST(BufferList, crc32c_append_perf) {
|
||||
TEST(BufferList, compare) {
|
||||
bufferlist a;
|
||||
a.append("A");
|
||||
bufferlist ab;
|
||||
ab.append("AB");
|
||||
bufferlist ab; // AB in segments
|
||||
ab.append(bufferptr("A", 1));
|
||||
ab.append(bufferptr("B", 1));
|
||||
bufferlist ac;
|
||||
ac.append("AC");
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user