Commit 88ab460c authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Adjust the constexpr strlen implementation to handle up to 4kb strings

Summary:
Previously it was only capable of handling 512 byte strings under MSVC due to the constexpr recursion depth limit being 512 by default under MSVC.
In the future once we have C++14 constexpr everywhere, this should just be a for loop, which should remove the limit.

Reviewed By: yfeldblum

Differential Revision: D9230717

fbshipit-source-id: 88bcf0ef94b200301eb41392482e910b2e8de008
parent 3795f900
......@@ -28,7 +28,18 @@ namespace detail {
template <typename Char>
constexpr size_t constexpr_strlen_internal(const Char* s, size_t len) {
return *s == Char(0) ? len : constexpr_strlen_internal(s + 1, len + 1);
// clang-format off
return
*(s + 0) == Char(0) ? len + 0 :
*(s + 1) == Char(0) ? len + 1 :
*(s + 2) == Char(0) ? len + 2 :
*(s + 3) == Char(0) ? len + 3 :
*(s + 4) == Char(0) ? len + 4 :
*(s + 5) == Char(0) ? len + 5 :
*(s + 6) == Char(0) ? len + 6 :
*(s + 7) == Char(0) ? len + 7 :
constexpr_strlen_internal(s + 8, len + 8);
// clang-format on
}
static_assert(
constexpr_strlen_internal("123456789", 0) == 9,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment