Commit fc10d0b8 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Apply clang-format to folly/**/*Range*.*

Summary: [Folly] Apply `clang-format` to `folly/**/*Range*.*`.

Reviewed By: meyering

Differential Revision: D5570553

fbshipit-source-id: 230aa8557c2d402d741aaa541f96f4634dd13d3b
parent e4c892c7
This diff is collapsed.
...@@ -24,7 +24,8 @@ namespace folly { ...@@ -24,7 +24,8 @@ namespace folly {
namespace detail { namespace detail {
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, size_t qfind_first_byte_of_bitset(
const StringPieceLite haystack,
const StringPieceLite needles) { const StringPieceLite needles) {
std::bitset<256> s; std::bitset<256> s;
for (auto needle : needles) { for (auto needle : needles) {
...@@ -38,10 +39,11 @@ size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, ...@@ -38,10 +39,11 @@ size_t qfind_first_byte_of_bitset(const StringPieceLite haystack,
return std::string::npos; return std::string::npos;
} }
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, size_t qfind_first_byte_of_byteset(
const StringPieceLite haystack,
const StringPieceLite needles) { const StringPieceLite needles) {
SparseByteSet s; SparseByteSet s;
for (auto needle: needles) { for (auto needle : needles) {
s.add(uint8_t(needle)); s.add(uint8_t(needle));
} }
for (size_t index = 0; index < haystack.size(); ++index) { for (size_t index = 0; index < haystack.size(); ++index) {
...@@ -51,7 +53,5 @@ size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, ...@@ -51,7 +53,5 @@ size_t qfind_first_byte_of_byteset(const StringPieceLite haystack,
} }
return std::string::npos; return std::string::npos;
} }
} }
} }
...@@ -38,37 +38,59 @@ class StringPieceLite { ...@@ -38,37 +38,59 @@ class StringPieceLite {
public: public:
StringPieceLite(const char* b, const char* e) : b_(b), e_(e) {} StringPieceLite(const char* b, const char* e) : b_(b), e_(e) {}
template <typename Range> template <typename Range>
/* implicit */ StringPieceLite(const Range& r) : /* implicit */ StringPieceLite(const Range& r)
StringPieceLite(r.data(), r.data() + r.size()) {} : StringPieceLite(r.data(), r.data() + r.size()) {}
const char* data() const { return b_; } const char* data() const {
const char* begin() const { return b_; } return b_;
const char* end() const { return e_; } }
size_t size() const { return size_t(e_ - b_); } const char* begin() const {
bool empty() const { return size() == 0; } return b_;
const char& operator[](size_t i) const { DCHECK_GT(size(), i); return b_[i]; } }
const char* end() const {
return e_;
}
size_t size() const {
return size_t(e_ - b_);
}
bool empty() const {
return size() == 0;
}
const char& operator[](size_t i) const {
DCHECK_GT(size(), i);
return b_[i];
}
template <typename Range> template <typename Range>
explicit operator Range() const { return Range(begin(), end()); } explicit operator Range() const {
return Range(begin(), end());
}
private: private:
const char* b_; const char* b_;
const char* e_; const char* e_;
}; };
inline size_t qfind_first_byte_of_std(const StringPieceLite haystack, inline size_t qfind_first_byte_of_std(
const StringPieceLite haystack,
const StringPieceLite needles) { const StringPieceLite needles) {
auto ret = std::find_first_of(haystack.begin(), haystack.end(), auto ret = std::find_first_of(
needles.begin(), needles.end(), haystack.begin(),
haystack.end(),
needles.begin(),
needles.end(),
[](char a, char b) { return a == b; }); [](char a, char b) { return a == b; });
return ret == haystack.end() ? std::string::npos : ret - haystack.begin(); return ret == haystack.end() ? std::string::npos : ret - haystack.begin();
} }
size_t qfind_first_byte_of_bitset(
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite haystack,
const StringPieceLite needles); const StringPieceLite needles);
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, size_t qfind_first_byte_of_byteset(
const StringPieceLite haystack,
const StringPieceLite needles); const StringPieceLite needles);
inline size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, inline size_t qfind_first_byte_of_nosse(
const StringPieceLite haystack,
const StringPieceLite needles) { const StringPieceLite needles) {
if (UNLIKELY(needles.empty() || haystack.empty())) { if (UNLIKELY(needles.empty() || haystack.empty())) {
return std::string::npos; return std::string::npos;
...@@ -77,13 +99,10 @@ inline size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, ...@@ -77,13 +99,10 @@ inline size_t qfind_first_byte_of_nosse(const StringPieceLite haystack,
// This is not an exact science since it depends on the CPU, the size of // This is not an exact science since it depends on the CPU, the size of
// needles, and the size of haystack. // needles, and the size of haystack.
if ((needles.size() >= 4 && haystack.size() <= 10) || if ((needles.size() >= 4 && haystack.size() <= 10) ||
(needles.size() >= 16 && haystack.size() <= 64) || (needles.size() >= 16 && haystack.size() <= 64) || needles.size() >= 32) {
needles.size() >= 32) {
return qfind_first_byte_of_byteset(haystack, needles); return qfind_first_byte_of_byteset(haystack, needles);
} }
return qfind_first_byte_of_std(haystack, needles); return qfind_first_byte_of_std(haystack, needles);
} }
} }
} }
...@@ -28,13 +28,14 @@ ...@@ -28,13 +28,14 @@
#if !FOLLY_SSE_PREREQ(4, 2) #if !FOLLY_SSE_PREREQ(4, 2)
namespace folly { namespace folly {
namespace detail { namespace detail {
size_t qfind_first_byte_of_sse42(const StringPieceLite haystack, size_t qfind_first_byte_of_sse42(
const StringPieceLite haystack,
const StringPieceLite needles) { const StringPieceLite needles) {
return qfind_first_byte_of_nosse(haystack, needles); return qfind_first_byte_of_nosse(haystack, needles);
} }
} }
} }
# else #else
#include <cstdint> #include <cstdint>
#include <limits> #include <limits>
#include <string> #include <string>
...@@ -49,15 +50,14 @@ size_t qfind_first_byte_of_sse42(const StringPieceLite haystack, ...@@ -49,15 +50,14 @@ size_t qfind_first_byte_of_sse42(const StringPieceLite haystack,
// a function with always_inline fails to build. The _mm_* functions are marked // a function with always_inline fails to build. The _mm_* functions are marked
// always_inline. // always_inline.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
#if defined FOLLY_SANITIZE_ADDRESS && \ #if defined FOLLY_SANITIZE_ADDRESS && FOLLY_SANITIZE_ADDRESS == 1 && \
FOLLY_SANITIZE_ADDRESS == 1 && \
__GNUC_PREREQ(4, 9) __GNUC_PREREQ(4, 9)
# define _mm_load_si128(p) (*(p)) #define _mm_load_si128(p) (*(p))
# define _mm_loadu_si128(p) ((__m128i)__builtin_ia32_loaddqu((const char*)(p))) #define _mm_loadu_si128(p) ((__m128i)__builtin_ia32_loaddqu((const char*)(p)))
# ifdef _mm_cmpestri #ifdef _mm_cmpestri
# undef _mm_cmpestri #undef _mm_cmpestri
# endif #endif
# define _mm_cmpestri(a, b, c, d, e) \ #define _mm_cmpestri(a, b, c, d, e) \
__builtin_ia32_pcmpestri128((__v16qi)(a), b, (__v16qi)(c), d, e) __builtin_ia32_pcmpestri128((__v16qi)(a), b, (__v16qi)(c), d, e)
#endif #endif
...@@ -67,7 +67,8 @@ namespace detail { ...@@ -67,7 +67,8 @@ namespace detail {
// It's okay if pages are bigger than this (as powers of two), but they should // It's okay if pages are bigger than this (as powers of two), but they should
// not be smaller. // not be smaller.
static constexpr size_t kMinPageSize = 4096; static constexpr size_t kMinPageSize = 4096;
static_assert(kMinPageSize >= 16, static_assert(
kMinPageSize >= 16,
"kMinPageSize must be at least SSE register size"); "kMinPageSize must be at least SSE register size");
template <typename T> template <typename T>
...@@ -82,12 +83,13 @@ static inline size_t nextAlignedIndex(const char* arr) { ...@@ -82,12 +83,13 @@ static inline size_t nextAlignedIndex(const char* arr) {
- firstPossible; - firstPossible;
} }
static size_t qfind_first_byte_of_needles16(const StringPieceLite haystack, static size_t qfind_first_byte_of_needles16(
const StringPieceLite needles) const StringPieceLite haystack,
FOLLY_DISABLE_ADDRESS_SANITIZER; const StringPieceLite needles) FOLLY_DISABLE_ADDRESS_SANITIZER;
// helper method for case where needles.size() <= 16 // helper method for case where needles.size() <= 16
size_t qfind_first_byte_of_needles16(const StringPieceLite haystack, size_t qfind_first_byte_of_needles16(
const StringPieceLite haystack,
const StringPieceLite needles) { const StringPieceLite needles) {
DCHECK_GT(haystack.size(), 0u); DCHECK_GT(haystack.size(), 0u);
DCHECK_GT(needles.size(), 0u); DCHECK_GT(needles.size(), 0u);
...@@ -101,11 +103,10 @@ size_t qfind_first_byte_of_needles16(const StringPieceLite haystack, ...@@ -101,11 +103,10 @@ size_t qfind_first_byte_of_needles16(const StringPieceLite haystack,
return detail::qfind_first_byte_of_nosse(haystack, needles); return detail::qfind_first_byte_of_nosse(haystack, needles);
} }
auto arr2 = _mm_loadu_si128( auto arr2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(needles.data()));
reinterpret_cast<const __m128i*>(needles.data()));
// do an unaligned load for first block of haystack // do an unaligned load for first block of haystack
auto arr1 = _mm_loadu_si128( auto arr1 =
reinterpret_cast<const __m128i*>(haystack.data())); _mm_loadu_si128(reinterpret_cast<const __m128i*>(haystack.data()));
auto index = auto index =
_mm_cmpestri(arr2, int(needles.size()), arr1, int(haystack.size()), 0); _mm_cmpestri(arr2, int(needles.size()), arr1, int(haystack.size()), 0);
if (index < 16) { if (index < 16) {
...@@ -114,7 +115,7 @@ size_t qfind_first_byte_of_needles16(const StringPieceLite haystack, ...@@ -114,7 +115,7 @@ size_t qfind_first_byte_of_needles16(const StringPieceLite haystack,
// Now, we can do aligned loads hereafter... // Now, we can do aligned loads hereafter...
size_t i = nextAlignedIndex(haystack.data()); size_t i = nextAlignedIndex(haystack.data());
for (; i < haystack.size(); i+= 16) { for (; i < haystack.size(); i += 16) {
arr1 = arr1 =
_mm_load_si128(reinterpret_cast<const __m128i*>(haystack.data() + i)); _mm_load_si128(reinterpret_cast<const __m128i*>(haystack.data() + i));
index = _mm_cmpestri( index = _mm_cmpestri(
...@@ -127,13 +128,14 @@ size_t qfind_first_byte_of_needles16(const StringPieceLite haystack, ...@@ -127,13 +128,14 @@ size_t qfind_first_byte_of_needles16(const StringPieceLite haystack,
} }
template <bool HAYSTACK_ALIGNED> template <bool HAYSTACK_ALIGNED>
size_t scanHaystackBlock(const StringPieceLite haystack, size_t scanHaystackBlock(
const StringPieceLite haystack,
const StringPieceLite needles, const StringPieceLite needles,
uint64_t idx) uint64_t idx)
// Turn off ASAN because the "arr2 = ..." assignment in the loop below reads // Turn off ASAN because the "arr2 = ..." assignment in the loop below reads
// up to 15 bytes beyond end of the buffer in #needles#. That is ok because // up to 15 bytes beyond end of the buffer in #needles#. That is ok because
// ptr2 is always 16-byte aligned, so the read can never span a page boundary. // ptr2 is always 16-byte aligned, so the read can never span a page
// Also, the extra data that may be read is never actually used. // boundary. Also, the extra data that may be read is never actually used.
FOLLY_DISABLE_ADDRESS_SANITIZER; FOLLY_DISABLE_ADDRESS_SANITIZER;
// Scans a 16-byte block of haystack (starting at blockStartIdx) to find first // Scans a 16-byte block of haystack (starting at blockStartIdx) to find first
...@@ -141,11 +143,13 @@ size_t scanHaystackBlock(const StringPieceLite haystack, ...@@ -141,11 +143,13 @@ size_t scanHaystackBlock(const StringPieceLite haystack,
// If !HAYSTACK_ALIGNED, then caller must ensure that it is safe to load the // If !HAYSTACK_ALIGNED, then caller must ensure that it is safe to load the
// block. // block.
template <bool HAYSTACK_ALIGNED> template <bool HAYSTACK_ALIGNED>
size_t scanHaystackBlock(const StringPieceLite haystack, size_t scanHaystackBlock(
const StringPieceLite haystack,
const StringPieceLite needles, const StringPieceLite needles,
uint64_t blockStartIdx) { uint64_t blockStartIdx) {
DCHECK_GT(needles.size(), 16u); // should handled by *needles16() method DCHECK_GT(needles.size(), 16u); // should handled by *needles16() method
DCHECK(blockStartIdx + 16 <= haystack.size() || DCHECK(
blockStartIdx + 16 <= haystack.size() ||
(page_for(haystack.data() + blockStartIdx) == (page_for(haystack.data() + blockStartIdx) ==
page_for(haystack.data() + blockStartIdx + 15))); page_for(haystack.data() + blockStartIdx + 15)));
...@@ -159,15 +163,13 @@ size_t scanHaystackBlock(const StringPieceLite haystack, ...@@ -159,15 +163,13 @@ size_t scanHaystackBlock(const StringPieceLite haystack,
} }
// This load is safe because needles.size() >= 16 // This load is safe because needles.size() >= 16
auto arr2 = _mm_loadu_si128( auto arr2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(needles.data()));
reinterpret_cast<const __m128i*>(needles.data()));
auto b = auto b =
_mm_cmpestri(arr2, 16, arr1, int(haystack.size() - blockStartIdx), 0); _mm_cmpestri(arr2, 16, arr1, int(haystack.size() - blockStartIdx), 0);
size_t j = nextAlignedIndex(needles.data()); size_t j = nextAlignedIndex(needles.data());
for (; j < needles.size(); j += 16) { for (; j < needles.size(); j += 16) {
arr2 = _mm_load_si128( arr2 = _mm_load_si128(reinterpret_cast<const __m128i*>(needles.data() + j));
reinterpret_cast<const __m128i*>(needles.data() + j));
auto index = _mm_cmpestri( auto index = _mm_cmpestri(
arr2, arr2,
...@@ -184,10 +186,12 @@ size_t scanHaystackBlock(const StringPieceLite haystack, ...@@ -184,10 +186,12 @@ size_t scanHaystackBlock(const StringPieceLite haystack,
return std::string::npos; return std::string::npos;
} }
size_t qfind_first_byte_of_sse42(const StringPieceLite haystack, size_t qfind_first_byte_of_sse42(
const StringPieceLite haystack,
const StringPieceLite needles); const StringPieceLite needles);
size_t qfind_first_byte_of_sse42(const StringPieceLite haystack, size_t qfind_first_byte_of_sse42(
const StringPieceLite haystack,
const StringPieceLite needles) { const StringPieceLite needles) {
if (UNLIKELY(needles.empty() || haystack.empty())) { if (UNLIKELY(needles.empty() || haystack.empty())) {
return std::string::npos; return std::string::npos;
......
...@@ -24,9 +24,8 @@ namespace folly { ...@@ -24,9 +24,8 @@ namespace folly {
namespace detail { namespace detail {
size_t qfind_first_byte_of_sse42(const StringPieceLite haystack, size_t qfind_first_byte_of_sse42(
const StringPieceLite haystack,
const StringPieceLite needles); const StringPieceLite needles);
} }
} }
...@@ -80,7 +80,6 @@ void initFile(int len) { ...@@ -80,7 +80,6 @@ void initFile(int len) {
} }
} }
string generateString(int len) { string generateString(int len) {
std::uniform_int_distribution<uint32_t> validChar(1, 255); // no null-char std::uniform_int_distribution<uint32_t> validChar(1, 255); // no null-char
string ret; string ret;
...@@ -305,7 +304,8 @@ BENCHMARK_RELATIVE(FindFirstOf32NeedlesBitSet, n) { ...@@ -305,7 +304,8 @@ BENCHMARK_RELATIVE(FindFirstOf32NeedlesBitSet, n) {
BENCHMARK_DRAW_LINE(); BENCHMARK_DRAW_LINE();
const string delims64 = "!bcdefghijklmnopqrstuvwxyz_" const string delims64 =
"!bcdefghijklmnopqrstuvwxyz_"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789$"; "ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789$";
BENCHMARK(FindFirstOf64NeedlesBase, n) { BENCHMARK(FindFirstOf64NeedlesBase, n) {
...@@ -400,7 +400,7 @@ BENCHMARK_DRAW_LINE(); ...@@ -400,7 +400,7 @@ BENCHMARK_DRAW_LINE();
int main(int argc, char** argv) { int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true); gflags::ParseCommandLineFlags(&argc, &argv, true);
for (int len : {1, 8, 10, 16, 32, 64, 128, 256, 10*1024, 1024*1024}) { for (int len : {1, 8, 10, 16, 32, 64, 128, 256, 10 * 1024, 1024 * 1024}) {
initStr(len); initStr(len);
initDelims(len); initDelims(len);
initFile(len); initFile(len);
......
...@@ -265,10 +265,10 @@ TEST(StringPiece, EightBitComparisons) { ...@@ -265,10 +265,10 @@ TEST(StringPiece, EightBitComparisons) {
TEST(StringPiece, ToByteRange) { TEST(StringPiece, ToByteRange) {
StringPiece a("hello"); StringPiece a("hello");
ByteRange b(a); ByteRange b(a);
EXPECT_EQ(static_cast<const void*>(a.begin()), EXPECT_EQ(
static_cast<const void*>(b.begin())); static_cast<const void*>(a.begin()), static_cast<const void*>(b.begin()));
EXPECT_EQ(static_cast<const void*>(a.end()), EXPECT_EQ(
static_cast<const void*>(b.end())); static_cast<const void*>(a.end()), static_cast<const void*>(b.end()));
// and convert back again // and convert back again
StringPiece c(b); StringPiece c(b);
...@@ -687,10 +687,10 @@ TEST(StringPiece, split_step_with_process_char_delimiter) { ...@@ -687,10 +687,10 @@ TEST(StringPiece, split_step_with_process_char_delimiter) {
return 9; return 9;
}))); })));
EXPECT_TRUE((std::is_same< EXPECT_TRUE(
(std::is_same<
void, void,
decltype(p.split_step(' ', split_step_with_process_noop)) decltype(p.split_step(' ', split_step_with_process_noop))>::value));
>::value));
EXPECT_NO_THROW(p.split_step(' ', split_step_with_process_noop)); EXPECT_NO_THROW(p.split_step(' ', split_step_with_process_noop));
} }
...@@ -777,10 +777,10 @@ TEST(StringPiece, split_step_with_process_range_delimiter) { ...@@ -777,10 +777,10 @@ TEST(StringPiece, split_step_with_process_range_delimiter) {
return 10; return 10;
}))); })));
EXPECT_TRUE((std::is_same< EXPECT_TRUE(
(std::is_same<
void, void,
decltype(p.split_step(' ', split_step_with_process_noop)) decltype(p.split_step(' ', split_step_with_process_noop))>::value));
>::value));
EXPECT_NO_THROW(p.split_step(' ', split_step_with_process_noop)); EXPECT_NO_THROW(p.split_step(' ', split_step_with_process_noop));
} }
...@@ -798,10 +798,7 @@ TEST(StringPiece, split_step_with_process_char_delimiter_additional_args) { ...@@ -798,10 +798,7 @@ TEST(StringPiece, split_step_with_process_char_delimiter_additional_args) {
EXPECT_EQ(e, p.end()); EXPECT_EQ(e, p.end());
EXPECT_EQ(s, p); EXPECT_EQ(s, p);
auto const functor = []( auto const functor = [](folly::StringPiece s, folly::StringPiece expected) {
folly::StringPiece s,
folly::StringPiece expected
) {
EXPECT_EQ(expected, s); EXPECT_EQ(expected, s);
return expected; return expected;
}; };
...@@ -836,10 +833,7 @@ TEST(StringPiece, split_step_with_process_range_delimiter_additional_args) { ...@@ -836,10 +833,7 @@ TEST(StringPiece, split_step_with_process_range_delimiter_additional_args) {
EXPECT_EQ(e, p.end()); EXPECT_EQ(e, p.end());
EXPECT_EQ(s, p); EXPECT_EQ(s, p);
auto const functor = []( auto const functor = [](folly::StringPiece s, folly::StringPiece expected) {
folly::StringPiece s,
folly::StringPiece expected
) {
EXPECT_EQ(expected, s); EXPECT_EQ(expected, s);
return expected; return expected;
}; };
...@@ -863,8 +857,12 @@ TEST(StringPiece, split_step_with_process_range_delimiter_additional_args) { ...@@ -863,8 +857,12 @@ TEST(StringPiece, split_step_with_process_range_delimiter_additional_args) {
TEST(StringPiece, NoInvalidImplicitConversions) { TEST(StringPiece, NoInvalidImplicitConversions) {
struct IsString { struct IsString {
bool operator()(folly::Range<int*>) { return false; } bool operator()(folly::Range<int*>) {
bool operator()(folly::StringPiece) { return true; } return false;
}
bool operator()(folly::StringPiece) {
return true;
}
}; };
std::string s = "hello"; std::string s = "hello";
...@@ -912,9 +910,8 @@ struct ByteSetNeedleFinder { ...@@ -912,9 +910,8 @@ struct ByteSetNeedleFinder {
} }
}; };
typedef ::testing::Types<SseNeedleFinder, using NeedleFinders =
NoSseNeedleFinder, ::testing::Types<SseNeedleFinder, NoSseNeedleFinder, ByteSetNeedleFinder>;
ByteSetNeedleFinder> NeedleFinders;
TYPED_TEST_CASE(NeedleFinderTest, NeedleFinders); TYPED_TEST_CASE(NeedleFinderTest, NeedleFinders);
TYPED_TEST(NeedleFinderTest, Null) { TYPED_TEST(NeedleFinderTest, Null) {
...@@ -1047,13 +1044,13 @@ TYPED_TEST(NeedleFinderTest, NoSegFault) { ...@@ -1047,13 +1044,13 @@ TYPED_TEST(NeedleFinderTest, NoSegFault) {
// string(s1.data(), s1.size()).c_str(), s1.size(), // string(s1.data(), s1.size()).c_str(), s1.size(),
// string(s2.data(), s2.size()).c_str(), s2.size()); // string(s2.data(), s2.size()).c_str(), s2.size());
auto r1 = this->find_first_byte_of(s1, s2); auto r1 = this->find_first_byte_of(s1, s2);
auto f1 = std::find_first_of(s1.begin(), s1.end(), auto f1 =
s2.begin(), s2.end()); std::find_first_of(s1.begin(), s1.end(), s2.begin(), s2.end());
auto e1 = (f1 == s1.end()) ? StringPiece::npos : f1 - s1.begin(); auto e1 = (f1 == s1.end()) ? StringPiece::npos : f1 - s1.begin();
EXPECT_EQ(r1, e1); EXPECT_EQ(r1, e1);
auto r2 = this->find_first_byte_of(s2, s1); auto r2 = this->find_first_byte_of(s2, s1);
auto f2 = std::find_first_of(s2.begin(), s2.end(), auto f2 =
s1.begin(), s1.end()); std::find_first_of(s2.begin(), s2.end(), s1.begin(), s1.end());
auto e2 = (f2 == s2.end()) ? StringPiece::npos : f2 - s2.begin(); auto e2 = (f2 == s2.end()) ? StringPiece::npos : f2 - s2.begin();
EXPECT_EQ(r2, e2); EXPECT_EQ(r2, e2);
freeProtectedBuf(buf1); freeProtectedBuf(buf1);
...@@ -1121,7 +1118,7 @@ TEST(RangeFunc, Array) { ...@@ -1121,7 +1118,7 @@ TEST(RangeFunc, Array) {
} }
TEST(RangeFunc, CArray) { TEST(RangeFunc, CArray) {
int x[] {1, 2, 3, 4}; int x[]{1, 2, 3, 4};
testRangeFunc(x, 4); testRangeFunc(x, 4);
} }
...@@ -1181,7 +1178,8 @@ TEST(RangeFunc, ConstexprCollection) { ...@@ -1181,7 +1178,8 @@ TEST(RangeFunc, ConstexprCollection) {
EXPECT_EQ(2, numCollRangeSize); EXPECT_EQ(2, numCollRangeSize);
} }
std::string get_rand_str(size_t size, std::string get_rand_str(
size_t size,
std::uniform_int_distribution<>& dist, std::uniform_int_distribution<>& dist,
std::mt19937& gen) { std::mt19937& gen) {
std::string ret(size, '\0'); std::string ret(size, '\0');
...@@ -1210,7 +1208,7 @@ TEST(ReplaceAt, exhaustiveTest) { ...@@ -1210,7 +1208,7 @@ TEST(ReplaceAt, exhaustiveTest) {
std::mt19937 gen(rd()); std::mt19937 gen(rd());
std::uniform_int_distribution<> dist('a', 'z'); std::uniform_int_distribution<> dist('a', 'z');
for (int i=0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
for (size_t j = 1; j <= msp.size(); ++j) { for (size_t j = 1; j <= msp.size(); ++j) {
auto replacement = get_rand_str(j, dist, gen); auto replacement = get_rand_str(j, dist, gen);
for (size_t pos = 0; pos < msp.size() - j; ++pos) { for (size_t pos = 0; pos < msp.size() - j; ++pos) {
...@@ -1266,7 +1264,7 @@ TEST(ReplaceAll, randomTest) { ...@@ -1266,7 +1264,7 @@ TEST(ReplaceAll, randomTest) {
std::mt19937 gen(rd()); std::mt19937 gen(rd());
std::uniform_int_distribution<> dist('A', 'Z'); std::uniform_int_distribution<> dist('A', 'Z');
for (int i=0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
for (size_t j = 1; j <= orig.size(); ++j) { for (size_t j = 1; j <= orig.size(); ++j) {
auto replacement = get_rand_str(j, dist, gen); auto replacement = get_rand_str(j, dist, gen);
for (size_t pos = 0; pos < msp.size() - j; ++pos) { for (size_t pos = 0; pos < msp.size() - j; ++pos) {
......
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