From: Hannes Roth Date: Mon, 7 Apr 2014 16:44:38 +0000 (-0700) Subject: (Folly/FBString) Fix compilation time of test with opt X-Git-Tag: v0.22.0~618 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a71d861b8d6a7162f61267d0fa8c53ecd1fec71b;p=folly.git (Folly/FBString) Fix compilation time of test with opt Summary: Now compiles in 18 seconds. Took two minutes before. Test Plan: `fbmake runtests_opt` Reviewed By: smith@fb.com FB internal diff: D1243689 --- diff --git a/folly/test/FBStringTest.cpp b/folly/test/FBStringTest.cpp index 89613635..950af58d 100644 --- a/folly/test/FBStringTest.cpp +++ b/folly/test/FBStringTest.cpp @@ -889,36 +889,47 @@ TEST(FBString, testAllClauses) { std::wstring wr; folly::fbstring c; folly::basic_fbstring wc; -#define TEST_CLAUSE(x) \ - do { \ - if (1) {} else EXPECT_TRUE(1) << "Testing clause " << #x; \ - randomString(&r); \ - c = r; \ - EXPECT_EQ(c, r); \ - wr = std::wstring(r.begin(), r.end()); \ - wc = folly::basic_fbstring(wr.c_str()); \ - auto localSeed = seed + count; \ - rng = RandomT(localSeed); \ - clause11_##x(r); \ - rng = RandomT(localSeed); \ - clause11_##x(c); \ - EXPECT_EQ(r, c) \ - << "Lengths: " << r.size() << " vs. " << c.size() \ - << "\nReference: '" << r << "'" \ - << "\nActual: '" << c.data()[0] << "'"; \ - rng = RandomT(localSeed); \ - clause11_##x(wc); \ - int wret = wcslen(wc.c_str()); \ - char mb[wret+1]; \ - int ret = wcstombs(mb, wc.c_str(), sizeof(mb)); \ - if (ret == wret) mb[wret] = '\0'; \ - const char *mc = c.c_str(); \ - std::string one(mb); \ - std::string two(mc); \ - EXPECT_EQ(one, two); \ - } while (++count % 100 != 0) - int count = 0; + + auto l = [&](const char * const clause, + void(*f_string)(std::string&), + void(*f_fbstring)(folly::fbstring&), + void(*f_wfbstring)(folly::basic_fbstring&)) { + do { + if (1) {} else EXPECT_TRUE(1) << "Testing clause " << clause; + randomString(&r); + c = r; + EXPECT_EQ(c, r); + wr = std::wstring(r.begin(), r.end()); + wc = folly::basic_fbstring(wr.c_str()); + auto localSeed = seed + count; + rng = RandomT(localSeed); + f_string(r); + rng = RandomT(localSeed); + f_fbstring(c); + EXPECT_EQ(r, c) + << "Lengths: " << r.size() << " vs. " << c.size() + << "\nReference: '" << r << "'" + << "\nActual: '" << c.data()[0] << "'"; + rng = RandomT(localSeed); + f_wfbstring(wc); + int wret = wcslen(wc.c_str()); + char mb[wret+1]; + int ret = wcstombs(mb, wc.c_str(), sizeof(mb)); + if (ret == wret) mb[wret] = '\0'; + const char *mc = c.c_str(); + std::string one(mb); + std::string two(mc); + EXPECT_EQ(one, two); + } while (++count % 100 != 0); + }; + +#define TEST_CLAUSE(x) \ + l(#x, \ + clause11_##x, \ + clause11_##x, \ + clause11_##x>); + TEST_CLAUSE(21_4_2_a); TEST_CLAUSE(21_4_2_b); TEST_CLAUSE(21_4_2_c);