Skip to content

Commit

Permalink
Missed C++20 (#435)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #435

LowerBoundPrefixMap now needs to be C++17 and I missed this one

Reviewed By: disylh, lenar-f

Differential Revision: D49559521

fbshipit-source-id: 9d9e4ac01c5c0c8c075e98730b3d6713c55ef63a
  • Loading branch information
DenisYaroshevskiy authored and facebook-github-bot committed Sep 23, 2023
1 parent a193a23 commit 11a1646
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions mcrouter/lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ libmcrouter_a_SOURCES = \
fbi/cpp/TypeList.h \
fbi/cpp/globals.cpp \
fbi/cpp/globals.h \
fbi/cpp/LowerBoundPrefixMap.cpp \
fbi/cpp/LowerBoundPrefixMap.h \
fbi/cpp/ParsingUtil.cpp \
fbi/cpp/ParsingUtil.h \
fbi/cpp/util.cpp \
Expand Down
22 changes: 14 additions & 8 deletions mcrouter/lib/fbi/cpp/LowerBoundPrefixMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@
#include <cstring>
#include <numeric>
#include <ostream>
#include <span>
#include <stdexcept>

#include <folly/CPortability.h>
#include <folly/Likely.h>

namespace facebook::memcache::detail {
namespace {

// .starts_with is not avaliable before C++20 and this needs to compile with an
// older standard
bool std_string_view_starts_with(std::string_view what, std::string_view with) {
return what.substr(0, with.size()) == with;
}

} // namespace

std::ostream& operator<<(std::ostream& os, const SmallPrefix& self) {
std::uint64_t correctOrder = folly::Endian::swap(self.data_);
Expand All @@ -32,12 +40,10 @@ LowerBoundPrefixMapCommon::LowerBoundPrefixMapCommon(

// total size
{
std::size_t size = std::transform_reduce(
sortedUniquePrefixes.begin(),
sortedUniquePrefixes.end(),
std::size_t{0},
std::plus<>{},
[](const auto& x) { return x.size(); });
std::size_t size = 0;
for (const auto& p : sortedUniquePrefixes) {
size += p.size();
}
if (size >= std::numeric_limits<std::uint32_t>::max()) {
throw std::runtime_error(
"too many chars for LowerBoundPrefixMap: " + std::to_string(size));
Expand Down Expand Up @@ -105,7 +111,7 @@ std::uint32_t LowerBoundPrefixMapCommon::findPrefix(
}) -
markers_.begin();

while (cur != 0 && !query.starts_with(str(cur - 1))) {
while (cur != 0 && !std_string_view_starts_with(query, str(cur - 1))) {
cur = previousPrefix_[cur - 1];
}

Expand Down
3 changes: 1 addition & 2 deletions mcrouter/lib/fbi/cpp/LowerBoundPrefixMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ struct LowerBoundPrefixMapCommon {

std::string_view str(std::uint32_t i) const {
const char* f = chars_.data() + markers_[i];
const char* l = chars_.data() + markers_[i + 1];
return std::string_view{f, l};
return std::string_view{f, markers_[i + 1] - markers_[i]};
}
};

Expand Down

0 comments on commit 11a1646

Please sign in to comment.