Export of internal Abseil changes

--
cfd7ee2487ed9b5636d8f83d3850c02e3b4a5cb0 by Jorg Brown <jorg@google.com>:

Add union padding to AsTree, to avoid issues on 32-bit MSVC 2015 compilers

alignas() causes compiler errors as per https://godbolt.org/z/vaTKjn
This change uses explicit padding to achieve what we want: https://godbolt.org/z/Mfjhhj

PiperOrigin-RevId: 353211413

--
b1ac7430ffdefe58c01b29e9acd182cda4630e1d by Jorg Brown <jorg@google.com>:

Make the casting functions flat() and ring() be static_cast, rather than reinterpret_cast.

PiperOrigin-RevId: 353149543

--
c37a6761c31720317c8b0b7db62b693643a88586 by Abseil Team <absl-team@google.com>:

Integrate CordRepRing logic into cord (but do not enable it)

PiperOrigin-RevId: 353135656

--
2007fd3045ed6285106795cf8f2e6d792922f5e8 by Abseil Team <absl-team@google.com>:

Fix a typo in the description of ::equal_range(). The correct return is actually a half-open range [first, last).

PiperOrigin-RevId: 353122213

--
6683fa2ba7271dd1f575bd7742d97f47a034c9d2 by Abseil Team <absl-team@google.com>:

Integrate CordRepRing logic into cord (but do not enable it)

PiperOrigin-RevId: 353121763
GitOrigin-RevId: cfd7ee2487ed9b5636d8f83d3850c02e3b4a5cb0
Change-Id: I6635163cd634706f5462c4065aa278e6bf193a72
pull/889/head
Abseil Team 4 years ago committed by Matt Kulukundis
parent 3a2d6572d0
commit e4e2e57e1a
  1. 7
      absl/container/btree_map.h
  2. 30
      absl/strings/internal/cord_internal.h
  3. 11
      absl/strings/internal/cord_rep_flat.h
  4. 11
      absl/strings/internal/cord_rep_ring.h

@ -384,9 +384,8 @@ class btree_map
// btree_map::equal_range() // btree_map::equal_range()
// //
// Returns a closed range [first, last], defined by a `std::pair` of two // Returns a half-open range [first, last), defined by a `std::pair` of two
// iterators, containing all elements with the passed key in the // iterators, containing all elements with the passed key in the `btree_map`.
// `btree_map`.
using Base::equal_range; using Base::equal_range;
// btree_map::find() // btree_map::find()
@ -709,7 +708,7 @@ class btree_multimap
// btree_multimap::equal_range() // btree_multimap::equal_range()
// //
// Returns a closed range [first, last], defined by a `std::pair` of two // Returns a half-open range [first, last), defined by a `std::pair` of two
// iterators, containing all elements with the passed key in the // iterators, containing all elements with the passed key in the
// `btree_multimap`. // `btree_multimap`.
using Base::equal_range; using Base::equal_range;

@ -456,8 +456,14 @@ class InlineData {
struct AsTree { struct AsTree {
explicit constexpr AsTree(absl::cord_internal::CordRep* tree) explicit constexpr AsTree(absl::cord_internal::CordRep* tree)
: rep(tree), cordz_info(kNullCordzInfo) {} : rep(tree), cordz_info(kNullCordzInfo) {}
absl::cord_internal::CordRep* rep; // This union uses up extra space so that whether rep is 32 or 64 bits,
alignas(sizeof(cordz_info_t)) cordz_info_t cordz_info; // cordz_info will still start at the eighth byte, and the last
// byte of cordz_info will still be the last byte of InlineData.
union {
absl::cord_internal::CordRep* rep;
cordz_info_t unused_aligner;
};
cordz_info_t cordz_info;
}; };
char& tag() { return reinterpret_cast<char*>(this)[kMaxInline]; } char& tag() { return reinterpret_cast<char*>(this)[kMaxInline]; }
@ -505,26 +511,6 @@ inline const CordRepExternal* CordRep::external() const {
return static_cast<const CordRepExternal*>(this); return static_cast<const CordRepExternal*>(this);
} }
inline CordRepFlat* CordRep::flat() {
assert(tag >= FLAT && tag <= MAX_FLAT_TAG);
return reinterpret_cast<CordRepFlat*>(this);
}
inline const CordRepFlat* CordRep::flat() const {
assert(tag >= FLAT && tag <= MAX_FLAT_TAG);
return reinterpret_cast<const CordRepFlat*>(this);
}
inline CordRepRing* CordRep::ring() {
assert(tag == RING);
return reinterpret_cast<CordRepRing*>(this);
}
inline const CordRepRing* CordRep::ring() const {
assert(tag == RING);
return reinterpret_cast<const CordRepRing*>(this);
}
inline CordRep* CordRep::Ref(CordRep* rep) { inline CordRep* CordRep::Ref(CordRep* rep) {
assert(rep != nullptr); assert(rep != nullptr);
rep->refcount.Increment(); rep->refcount.Increment();

@ -127,6 +127,17 @@ struct CordRepFlat : public CordRep {
size_t AllocatedSize() const { return TagToAllocatedSize(tag); } size_t AllocatedSize() const { return TagToAllocatedSize(tag); }
}; };
// Now that CordRepFlat is defined, we can define CordRep's helper casts:
inline CordRepFlat* CordRep::flat() {
assert(tag >= FLAT && tag <= MAX_FLAT_TAG);
return reinterpret_cast<CordRepFlat*>(this);
}
inline const CordRepFlat* CordRep::flat() const {
assert(tag >= FLAT && tag <= MAX_FLAT_TAG);
return reinterpret_cast<const CordRepFlat*>(this);
}
} // namespace cord_internal } // namespace cord_internal
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl

@ -563,6 +563,17 @@ inline CordRepRing::Position CordRepRing::FindTail(index_type head,
return (offset == length) ? Position{tail_, 0} : FindTailSlow(head, offset); return (offset == length) ? Position{tail_, 0} : FindTailSlow(head, offset);
} }
// Now that CordRepRing is defined, we can define CordRep's helper casts:
inline CordRepRing* CordRep::ring() {
assert(tag == RING);
return static_cast<CordRepRing*>(this);
}
inline const CordRepRing* CordRep::ring() const {
assert(tag == RING);
return static_cast<const CordRepRing*>(this);
}
std::ostream& operator<<(std::ostream& s, const CordRepRing& rep); std::ostream& operator<<(std::ostream& s, const CordRepRing& rep);
#ifdef __clang__ #ifdef __clang__

Loading…
Cancel
Save