Export of internal Abseil changes.
-- 6bab63b2bcdbd768743c2ebcc4a8e19af20c5406 by Abseil Team <absl-team@google.com>: Reformats inlined_vector.h to match the current Google lint rules PiperOrigin-RevId: 202154101 -- 00cdeda6ea24591a9cb8ac8b3c2e2a042e1b15b1 by Gennadiy Rozental <rogeeff@google.com>: Improve SplitterIsConvertibleTo implementation. PiperOrigin-RevId: 202095009 -- 7c24071afac45a17c47e819896f844a36e239bda by Greg Falcon <gfalcon@google.com>: Internal change PiperOrigin-RevId: 201991288 GitOrigin-RevId: 6bab63b2bcdbd768743c2ebcc4a8e19af20c5406 Change-Id: Ic5a988ab39e78247285411f36287cd34d6f5afd3
This commit is contained in:
		
							parent
							
								
									87a4c07856
								
							
						
					
					
						commit
						7efd8dc0f1
					
				
					 7 changed files with 65 additions and 20 deletions
				
			
		| 
						 | 
				
			
			@ -387,6 +387,7 @@ cc_test(
 | 
			
		|||
        "//absl:windows": [],
 | 
			
		||||
        "//conditions:default": ["-pthread"],
 | 
			
		||||
    }),
 | 
			
		||||
    tags = ["no_test_ios_x86_64"],
 | 
			
		||||
    deps = [":malloc_internal"],
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -645,12 +645,12 @@ class InlinedVector {
 | 
			
		|||
  class AllocatorAndTag : private allocator_type {
 | 
			
		||||
   public:
 | 
			
		||||
    explicit AllocatorAndTag(const allocator_type& a, Tag t = Tag())
 | 
			
		||||
        : allocator_type(a), tag_(t) {
 | 
			
		||||
    }
 | 
			
		||||
        : allocator_type(a), tag_(t) {}
 | 
			
		||||
    Tag& tag() { return tag_; }
 | 
			
		||||
    const Tag& tag() const { return tag_; }
 | 
			
		||||
    allocator_type& allocator() { return *this; }
 | 
			
		||||
    const allocator_type& allocator() const { return *this; }
 | 
			
		||||
 | 
			
		||||
   private:
 | 
			
		||||
    Tag tag_;
 | 
			
		||||
  };
 | 
			
		||||
| 
						 | 
				
			
			@ -696,19 +696,13 @@ class InlinedVector {
 | 
			
		|||
    return reinterpret_cast<const value_type*>(&rep_.inlined_storage.inlined);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  value_type* allocated_space() {
 | 
			
		||||
    return allocation().buffer();
 | 
			
		||||
  }
 | 
			
		||||
  const value_type* allocated_space() const {
 | 
			
		||||
    return allocation().buffer();
 | 
			
		||||
  }
 | 
			
		||||
  value_type* allocated_space() { return allocation().buffer(); }
 | 
			
		||||
  const value_type* allocated_space() const { return allocation().buffer(); }
 | 
			
		||||
 | 
			
		||||
  const allocator_type& allocator() const {
 | 
			
		||||
    return allocator_and_tag_.allocator();
 | 
			
		||||
  }
 | 
			
		||||
  allocator_type& allocator() {
 | 
			
		||||
    return allocator_and_tag_.allocator();
 | 
			
		||||
  }
 | 
			
		||||
  allocator_type& allocator() { return allocator_and_tag_.allocator(); }
 | 
			
		||||
 | 
			
		||||
  bool allocated() const { return tag().allocated(); }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1128,8 +1122,7 @@ void InlinedVector<T, N, A>::swap(InlinedVector& other) {
 | 
			
		|||
    const size_type b_size = b->size();
 | 
			
		||||
    assert(a_size >= b_size);
 | 
			
		||||
    // 'a' is larger. Swap the elements up to the smaller array size.
 | 
			
		||||
    std::swap_ranges(a->inlined_space(),
 | 
			
		||||
                     a->inlined_space() + b_size,
 | 
			
		||||
    std::swap_ranges(a->inlined_space(), a->inlined_space() + b_size,
 | 
			
		||||
                     b->inlined_space());
 | 
			
		||||
 | 
			
		||||
    // Move the remaining elements: A[b_size,a_size) -> B[b_size,a_size)
 | 
			
		||||
| 
						 | 
				
			
			@ -1273,8 +1266,7 @@ void InlinedVector<T, N, A>::Destroy(value_type* ptr, value_type* ptr_last) {
 | 
			
		|||
  // scribbling on a vtable pointer.
 | 
			
		||||
#ifndef NDEBUG
 | 
			
		||||
  if (ptr != ptr_last) {
 | 
			
		||||
    memset(reinterpret_cast<void*>(ptr), 0xab,
 | 
			
		||||
           sizeof(*ptr) * (ptr_last - ptr));
 | 
			
		||||
    memset(reinterpret_cast<void*>(ptr), 0xab, sizeof(*ptr) * (ptr_last - ptr));
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1302,8 +1294,9 @@ void InlinedVector<T, N, A>::AssignRange(Iter first, Iter last,
 | 
			
		|||
  // Optimized to avoid reallocation.
 | 
			
		||||
  // Prefer reassignment to copy construction for elements.
 | 
			
		||||
  iterator out = begin();
 | 
			
		||||
  for ( ; first != last && out != end(); ++first, ++out)
 | 
			
		||||
  for (; first != last && out != end(); ++first, ++out) {
 | 
			
		||||
    *out = *first;
 | 
			
		||||
  }
 | 
			
		||||
  erase(out, end());
 | 
			
		||||
  std::copy(first, last, std::back_inserter(*this));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -486,6 +486,9 @@ cc_test(
 | 
			
		|||
    srcs = [
 | 
			
		||||
        "charconv_benchmark.cc",
 | 
			
		||||
    ],
 | 
			
		||||
    tags = [
 | 
			
		||||
        "benchmark",
 | 
			
		||||
    ],
 | 
			
		||||
    deps = [
 | 
			
		||||
        ":strings",
 | 
			
		||||
        "//absl/base",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -228,14 +228,31 @@ struct IsInitializerList
 | 
			
		|||
// compiled in C++11 will get an error due to ambiguous conversion paths (in
 | 
			
		||||
// C++11 std::vector<T>::operator= is overloaded to take either a std::vector<T>
 | 
			
		||||
// or an std::initializer_list<T>).
 | 
			
		||||
 | 
			
		||||
template <typename C, bool has_value_type, bool has_mapped_type>
 | 
			
		||||
struct SplitterIsConvertibleToImpl : std::false_type {};
 | 
			
		||||
 | 
			
		||||
template <typename C>
 | 
			
		||||
struct SplitterIsConvertibleToImpl<C, true, false>
 | 
			
		||||
    : std::is_constructible<typename C::value_type, absl::string_view> {};
 | 
			
		||||
 | 
			
		||||
template <typename C>
 | 
			
		||||
struct SplitterIsConvertibleToImpl<C, true, true>
 | 
			
		||||
    : absl::conjunction<
 | 
			
		||||
          std::is_constructible<typename C::key_type, absl::string_view>,
 | 
			
		||||
          std::is_constructible<typename C::mapped_type, absl::string_view>> {};
 | 
			
		||||
 | 
			
		||||
template <typename C>
 | 
			
		||||
struct SplitterIsConvertibleTo
 | 
			
		||||
    : std::enable_if<
 | 
			
		||||
    : SplitterIsConvertibleToImpl<
 | 
			
		||||
          C,
 | 
			
		||||
#ifdef _GLIBCXX_DEBUG
 | 
			
		||||
          !IsStrictlyBaseOfAndConvertibleToSTLContainer<C>::value &&
 | 
			
		||||
#endif  // _GLIBCXX_DEBUG
 | 
			
		||||
          !IsInitializerList<C>::value && HasValueType<C>::value &&
 | 
			
		||||
          HasConstIterator<C>::value> {
 | 
			
		||||
              !IsInitializerList<
 | 
			
		||||
                  typename std::remove_reference<C>::type>::value &&
 | 
			
		||||
              HasValueType<C>::value && HasConstIterator<C>::value,
 | 
			
		||||
          HasMappedType<C>::value> {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// This class implements the range that is returned by absl::StrSplit(). This
 | 
			
		||||
| 
						 | 
				
			
			@ -281,7 +298,8 @@ class Splitter {
 | 
			
		|||
  // An implicit conversion operator that is restricted to only those containers
 | 
			
		||||
  // that the splitter is convertible to.
 | 
			
		||||
  template <typename Container,
 | 
			
		||||
            typename OnlyIf = typename SplitterIsConvertibleTo<Container>::type>
 | 
			
		||||
            typename = typename std::enable_if<
 | 
			
		||||
                SplitterIsConvertibleTo<Container>::value>::type>
 | 
			
		||||
  operator Container() const {  // NOLINT(runtime/explicit)
 | 
			
		||||
    return ConvertToContainer<Container, typename Container::value_type,
 | 
			
		||||
                              HasMappedType<Container>::value>()(*this);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,6 +37,34 @@ using ::testing::ElementsAre;
 | 
			
		|||
using ::testing::Pair;
 | 
			
		||||
using ::testing::UnorderedElementsAre;
 | 
			
		||||
 | 
			
		||||
TEST(Split, TraitsTest) {
 | 
			
		||||
  static_assert(!absl::strings_internal::SplitterIsConvertibleTo<int>::value,
 | 
			
		||||
                "");
 | 
			
		||||
  static_assert(!absl::strings_internal::SplitterIsConvertibleTo<std::string>::value,
 | 
			
		||||
                "");
 | 
			
		||||
  static_assert(absl::strings_internal::SplitterIsConvertibleTo<
 | 
			
		||||
                    std::vector<std::string>>::value,
 | 
			
		||||
                "");
 | 
			
		||||
  static_assert(
 | 
			
		||||
      !absl::strings_internal::SplitterIsConvertibleTo<std::vector<int>>::value,
 | 
			
		||||
      "");
 | 
			
		||||
  static_assert(absl::strings_internal::SplitterIsConvertibleTo<
 | 
			
		||||
                    std::vector<absl::string_view>>::value,
 | 
			
		||||
                "");
 | 
			
		||||
  static_assert(absl::strings_internal::SplitterIsConvertibleTo<
 | 
			
		||||
                    std::map<std::string, std::string>>::value,
 | 
			
		||||
                "");
 | 
			
		||||
  static_assert(absl::strings_internal::SplitterIsConvertibleTo<
 | 
			
		||||
                    std::map<absl::string_view, absl::string_view>>::value,
 | 
			
		||||
                "");
 | 
			
		||||
  static_assert(!absl::strings_internal::SplitterIsConvertibleTo<
 | 
			
		||||
                    std::map<int, std::string>>::value,
 | 
			
		||||
                "");
 | 
			
		||||
  static_assert(!absl::strings_internal::SplitterIsConvertibleTo<
 | 
			
		||||
                    std::map<std::string, int>>::value,
 | 
			
		||||
                "");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// This tests the overall split API, which is made up of the absl::StrSplit()
 | 
			
		||||
// function and the Delimiter objects in the absl:: namespace.
 | 
			
		||||
// This TEST macro is outside of any namespace to require full specification of
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -225,6 +225,7 @@ cc_test(
 | 
			
		|||
        "//absl:windows": [],
 | 
			
		||||
        "//conditions:default": ["-pthread"],
 | 
			
		||||
    }),
 | 
			
		||||
    tags = ["no_test_ios_x86_64"],
 | 
			
		||||
    deps = [
 | 
			
		||||
        ":synchronization",
 | 
			
		||||
        "//absl/base",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -256,6 +256,7 @@ cc_test(
 | 
			
		|||
        "variant_benchmark.cc",
 | 
			
		||||
    ],
 | 
			
		||||
    copts = ABSL_TEST_COPTS,
 | 
			
		||||
    tags = ["benchmark"],
 | 
			
		||||
    deps = [
 | 
			
		||||
        ":variant",
 | 
			
		||||
        "//absl/utility",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue