Commit faaf3a5d authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

A few nits for constexpr_strlen, constexpr_strcmp

Summary: [Folly] A few nits for `constexpr_strlen`, `constexpr_strcmp`.

Reviewed By: ericniebler

Differential Revision: D23547224

fbshipit-source-id: f232861f5cc4dbd5eb77c4bbe3b9766fd233e9f5
parent d6931011
...@@ -43,14 +43,15 @@ namespace detail { ...@@ -43,14 +43,15 @@ namespace detail {
// yields a compile-time constant. // yields a compile-time constant.
template < template <
typename Char, typename Char,
size_t = FOLLY_DETAIL_STRLEN(static_cast<const Char*>(""))> std::size_t = FOLLY_DETAIL_STRLEN(static_cast<const Char*>(""))>
constexpr std::size_t constexpr_strlen_internal(const Char* s, int) noexcept { constexpr std::size_t constexpr_strlen_internal(const Char* s, int) noexcept {
return FOLLY_DETAIL_STRLEN(s); return FOLLY_DETAIL_STRLEN(s);
} }
template <typename Char> template <typename Char>
constexpr std::size_t constexpr_strlen_internal( constexpr std::size_t constexpr_strlen_internal(
const Char* s, const Char* s,
std::size_t ret) noexcept { unsigned) noexcept {
std::size_t ret = 0;
while (*s++) { while (*s++) {
++ret; ++ret;
} }
...@@ -58,8 +59,8 @@ constexpr std::size_t constexpr_strlen_internal( ...@@ -58,8 +59,8 @@ constexpr std::size_t constexpr_strlen_internal(
} }
template <typename Char> template <typename Char>
constexpr size_t constexpr_strlen_fallback(const Char* s) noexcept { constexpr std::size_t constexpr_strlen_fallback(const Char* s) noexcept {
return constexpr_strlen_internal(s, (std::size_t)0); return constexpr_strlen_internal(s, 0u);
} }
static_assert( static_assert(
...@@ -76,10 +77,8 @@ constexpr_strcmp_internal(const Char* s1, const Char* s2, int) noexcept { ...@@ -76,10 +77,8 @@ constexpr_strcmp_internal(const Char* s1, const Char* s2, int) noexcept {
return FOLLY_DETAIL_STRCMP(s1, s2); return FOLLY_DETAIL_STRCMP(s1, s2);
} }
template <typename Char> template <typename Char>
constexpr int constexpr_strcmp_internal( constexpr int
const Char* s1, constexpr_strcmp_internal(const Char* s1, const Char* s2, unsigned) noexcept {
const Char* s2,
std::size_t) noexcept {
while (*s1 && *s1 == *s2) { while (*s1 && *s1 == *s2) {
++s1, ++s2; ++s1, ++s2;
} }
...@@ -91,7 +90,7 @@ template <typename Char> ...@@ -91,7 +90,7 @@ template <typename Char>
constexpr int constexpr_strcmp_fallback( constexpr int constexpr_strcmp_fallback(
const Char* s1, const Char* s1,
const Char* s2) noexcept { const Char* s2) noexcept {
return constexpr_strcmp_internal(s1, s2, (std::size_t)0); return constexpr_strcmp_internal(s1, s2, 0u);
} }
#undef FOLLY_DETAIL_STRCMP #undef FOLLY_DETAIL_STRCMP
...@@ -100,12 +99,12 @@ constexpr int constexpr_strcmp_fallback( ...@@ -100,12 +99,12 @@ constexpr int constexpr_strcmp_fallback(
} // namespace detail } // namespace detail
template <typename Char> template <typename Char>
constexpr size_t constexpr_strlen(const Char* s) noexcept { constexpr std::size_t constexpr_strlen(const Char* s) noexcept {
return ::folly::detail::constexpr_strlen_internal(s, 0); return detail::constexpr_strlen_internal(s, 0);
} }
template <typename Char> template <typename Char>
constexpr int constexpr_strcmp(const Char* s1, const Char* s2) noexcept { constexpr int constexpr_strcmp(const Char* s1, const Char* s2) noexcept {
return ::folly::detail::constexpr_strcmp_internal(s1, s2, 0); return detail::constexpr_strcmp_internal(s1, s2, 0);
} }
} // namespace folly } // namespace folly
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