diff --git a/mcrouter/lib/Makefile.am b/mcrouter/lib/Makefile.am index 3fe806d91..5efcd073a 100644 --- a/mcrouter/lib/Makefile.am +++ b/mcrouter/lib/Makefile.am @@ -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 \ diff --git a/mcrouter/lib/fbi/cpp/LowerBoundPrefixMap.cpp b/mcrouter/lib/fbi/cpp/LowerBoundPrefixMap.cpp index f05d8d37b..b8b3405c5 100644 --- a/mcrouter/lib/fbi/cpp/LowerBoundPrefixMap.cpp +++ b/mcrouter/lib/fbi/cpp/LowerBoundPrefixMap.cpp @@ -10,13 +10,21 @@ #include #include #include -#include #include #include #include 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_); @@ -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::max()) { throw std::runtime_error( "too many chars for LowerBoundPrefixMap: " + std::to_string(size)); @@ -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]; } diff --git a/mcrouter/lib/fbi/cpp/LowerBoundPrefixMap.h b/mcrouter/lib/fbi/cpp/LowerBoundPrefixMap.h index 7c7f7124d..ffa887be5 100644 --- a/mcrouter/lib/fbi/cpp/LowerBoundPrefixMap.h +++ b/mcrouter/lib/fbi/cpp/LowerBoundPrefixMap.h @@ -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]}; } };