No need to export global instances of folly::AsciiCase(Ins|S)ensitive
authorYedidya Feldblum <yfeldblum@fb.com>
Tue, 15 Sep 2015 20:21:25 +0000 (13:21 -0700)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Tue, 15 Sep 2015 21:20:18 +0000 (14:20 -0700)
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

folly/Range.cpp
folly/Range.h
folly/test/RangeFindBenchmark.cpp

index bf4e28d0f7f23954e39e7d96a8cff9ffde2a6aa6..b11dfc45229b0efd4b18664e7bb6b20b6e0bfbe2 100644 (file)
 
 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
index 1088f4662c5506fcfcbe9347432c32c18c85c66d..3f312fe1fdd6e5b56ac46f87c2096e452a5d27ff 100644 (file)
@@ -1055,9 +1055,6 @@ struct AsciiCaseInsensitive {
   }
 };
 
-extern const AsciiCaseSensitive asciiCaseSensitive;
-extern const AsciiCaseInsensitive asciiCaseInsensitive;
-
 template <class T>
 size_t qfind(const Range<T>& haystack,
              const typename Range<T>::value_type& needle) {
@@ -1115,7 +1112,7 @@ inline size_t rfind(const Range<const unsigned char*>& haystack,
 template <class T>
 size_t qfind_first_of(const Range<T>& haystack,
                       const Range<T>& needles) {
-  return qfind_first_of(haystack, needles, asciiCaseSensitive);
+  return qfind_first_of(haystack, needles, AsciiCaseSensitive());
 }
 
 // specialization for StringPiece
index 7ad15ae34f43ebbf82d2d16bef5b903638d985f1..7d7a872d99340a48fd50fcd3afb216f2198f9b68 100644 (file)
@@ -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 <class Func>