From: Yedidya Feldblum Date: Tue, 15 Sep 2015 20:21:25 +0000 (-0700) Subject: No need to export global instances of folly::AsciiCase(Ins|S)ensitive X-Git-Tag: deprecate-dynamic-initializer~403 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=40673e015ab66a54ea900c89a9e367819f389d45;p=folly.git No need to export global instances of folly::AsciiCase(Ins|S)ensitive Summary: [Folly] No need to export global instances of `folly::AsciiCaseInsensitive` and `folly::AsciiCaseSensitive`. Calling code may simply construct instances at will - the compiler will optimize away the object construction since it has only the default ctor/dtor, no storage, and no vtable. Reviewed By: @fugalh Differential Revision: D2437419 --- diff --git a/folly/Range.cpp b/folly/Range.cpp index bf4e28d0..b11dfc45 100644 --- a/folly/Range.cpp +++ b/folly/Range.cpp @@ -26,12 +26,6 @@ namespace folly { -/** - * Predicates that can be used with qfind and startsWith - */ -const AsciiCaseSensitive asciiCaseSensitive = AsciiCaseSensitive(); -const AsciiCaseInsensitive asciiCaseInsensitive = AsciiCaseInsensitive(); - namespace { // It's okay if pages are bigger than this (as powers of two), but they should @@ -216,7 +210,7 @@ size_t qfind_first_byte_of_sse42(const StringPiece haystack, PAGE_FOR(haystack.end() - 1) != PAGE_FOR(haystack.data() + 16)) { // We can't safely SSE-load haystack. Use a different approach. if (haystack.size() <= 2) { - return qfind_first_of(haystack, needles, asciiCaseSensitive); + return qfind_first_of(haystack, needles, AsciiCaseSensitive()); } return qfind_first_byte_of_byteset(haystack, needles); } @@ -251,7 +245,7 @@ size_t qfind_first_byte_of_nosse(const StringPiece haystack, needles.size() >= 32) { return qfind_first_byte_of_byteset(haystack, needles); } - return qfind_first_of(haystack, needles, asciiCaseSensitive); + return qfind_first_of(haystack, needles, AsciiCaseSensitive()); } } // namespace detail diff --git a/folly/Range.h b/folly/Range.h index 1088f466..3f312fe1 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -1055,9 +1055,6 @@ struct AsciiCaseInsensitive { } }; -extern const AsciiCaseSensitive asciiCaseSensitive; -extern const AsciiCaseInsensitive asciiCaseInsensitive; - template size_t qfind(const Range& haystack, const typename Range::value_type& needle) { @@ -1115,7 +1112,7 @@ inline size_t rfind(const Range& haystack, template size_t qfind_first_of(const Range& haystack, const Range& needles) { - return qfind_first_of(haystack, needles, asciiCaseSensitive); + return qfind_first_of(haystack, needles, AsciiCaseSensitive()); } // specialization for StringPiece diff --git a/folly/test/RangeFindBenchmark.cpp b/folly/test/RangeFindBenchmark.cpp index 7ad15ae3..7d7a872d 100644 --- a/folly/test/RangeFindBenchmark.cpp +++ b/folly/test/RangeFindBenchmark.cpp @@ -144,7 +144,7 @@ BENCHMARK_DRAW_LINE(); // it's useful to compare our custom implementations vs. the standard library inline size_t qfind_first_byte_of_std(const StringPiece haystack, const StringPiece needles) { - return qfind_first_of(haystack, needles, asciiCaseSensitive); + return qfind_first_of(haystack, needles, AsciiCaseSensitive()); } template