Avoid copies in Facade

This commit is contained in:
2024-05-23 17:27:55 -07:00
parent 2764a049a8
commit b5dbf4a049
3 changed files with 48 additions and 15 deletions

View File

@@ -5,6 +5,9 @@
#include <algorithm>
#include <string.h>
#include <string>
using String = std::basic_string<uint8_t>;
inline auto operator<=>(const weaselab::VersionedMap::Key &lhs,
const weaselab::VersionedMap::Key &rhs) {
int cl = std::min(lhs.len, rhs.len);
@@ -16,3 +19,25 @@ inline auto operator<=>(const weaselab::VersionedMap::Key &lhs,
}
return lhs.len <=> rhs.len;
}
inline auto operator<=>(const String &lhs,
const weaselab::VersionedMap::Key &rhs) {
int cl = std::min<int>(lhs.size(), rhs.len);
if (cl > 0) {
int c = memcmp(lhs.data(), rhs.p, cl);
if (c != 0) {
return c <=> 0;
}
}
return int(lhs.size()) <=> rhs.len;
}
inline auto operator==(const weaselab::VersionedMap::Key &lhs,
const weaselab::VersionedMap::Key &rhs) {
return (lhs <=> rhs) == 0;
}
inline auto operator!=(const weaselab::VersionedMap::Key &lhs,
const weaselab::VersionedMap::Key &rhs) {
return (lhs <=> rhs) != 0;
}