Commit acf3390c by Abseil Team Committed by Greg Falcon

Export of internal Abseil changes

--
8ebcdcac49f299156a8fd4a77501a258050960e8 by Evan Brown <ezb@google.com>:

In btree_iterator, refactor a bit and update a couple of comments.

PiperOrigin-RevId: 345491436

--
421d3b9b5cf484811b9514436ce83f797e109145 by CJ Johnson <johnsoncj@google.com>:

Updates the implementation of InlinedVector to accurately express the value-initialization semantics of the default constructor

PiperOrigin-RevId: 345479151

--
88f36a132b2038cb276ed1ad4d9764adb1fc78e6 by CJ Johnson <johnsoncj@google.com>:

Updates the implementation of InlinedVector to accurately express the value-initialization semantics of the default constructor

PiperOrigin-RevId: 345433064

--
e55c9b4e7c578c1c4f2df65b1991041c283a97d9 by Chris Kennelly <ckennelly@google.com>:

Internal change

PiperOrigin-RevId: 345388181

--
e2284c4e77ff1ebc3009e5bf520524c552226d8a by Chris Kennelly <ckennelly@google.com>:

Internal change

PiperOrigin-RevId: 345357514

--
1c496a2ae07ce98578614155d63ef2ea4de5e518 by Chris Kennelly <ckennelly@google.com>:

Mark string lookup functions noexcept.

PiperOrigin-RevId: 345275012
GitOrigin-RevId: 8ebcdcac49f299156a8fd4a77501a258050960e8
Change-Id: I0ccb57d210b543270769e1378de38bf0922f8745
parent 59292448
...@@ -910,6 +910,7 @@ struct btree_iterator { ...@@ -910,6 +910,7 @@ struct btree_iterator {
using key_type = typename Node::key_type; using key_type = typename Node::key_type;
using size_type = typename Node::size_type; using size_type = typename Node::size_type;
using params_type = typename Node::params_type; using params_type = typename Node::params_type;
using is_map_container = typename params_type::is_map_container;
using node_type = Node; using node_type = Node;
using normal_node = typename std::remove_const<Node>::type; using normal_node = typename std::remove_const<Node>::type;
...@@ -921,7 +922,7 @@ struct btree_iterator { ...@@ -921,7 +922,7 @@ struct btree_iterator {
using slot_type = typename params_type::slot_type; using slot_type = typename params_type::slot_type;
using iterator = using iterator =
btree_iterator<normal_node, normal_reference, normal_pointer>; btree_iterator<normal_node, normal_reference, normal_pointer>;
using const_iterator = using const_iterator =
btree_iterator<const_node, const_reference, const_pointer>; btree_iterator<const_node, const_reference, const_pointer>;
...@@ -938,20 +939,19 @@ struct btree_iterator { ...@@ -938,20 +939,19 @@ struct btree_iterator {
btree_iterator(Node *n, int p) : node(n), position(p) {} btree_iterator(Node *n, int p) : node(n), position(p) {}
// NOTE: this SFINAE allows for implicit conversions from iterator to // NOTE: this SFINAE allows for implicit conversions from iterator to
// const_iterator, but it specifically avoids defining copy constructors so // const_iterator, but it specifically avoids hiding the copy constructor so
// that btree_iterator can be trivially copyable. This is for performance and // that the trivial one will be used when possible.
// binary size reasons.
template <typename N, typename R, typename P, template <typename N, typename R, typename P,
absl::enable_if_t< absl::enable_if_t<
std::is_same<btree_iterator<N, R, P>, iterator>::value && std::is_same<btree_iterator<N, R, P>, iterator>::value &&
std::is_same<btree_iterator, const_iterator>::value, std::is_same<btree_iterator, const_iterator>::value,
int> = 0> int> = 0>
btree_iterator(const btree_iterator<N, R, P> &other) // NOLINT btree_iterator(const btree_iterator<N, R, P> other) // NOLINT
: node(other.node), position(other.position) {} : node(other.node), position(other.position) {}
private: private:
// This SFINAE allows explicit conversions from const_iterator to // This SFINAE allows explicit conversions from const_iterator to
// iterator, but also avoids defining a copy constructor. // iterator, but also avoids hiding the copy constructor.
// NOTE: the const_cast is safe because this constructor is only called by // NOTE: the const_cast is safe because this constructor is only called by
// non-const methods and the container owns the nodes. // non-const methods and the container owns the nodes.
template <typename N, typename R, typename P, template <typename N, typename R, typename P,
...@@ -959,7 +959,7 @@ struct btree_iterator { ...@@ -959,7 +959,7 @@ struct btree_iterator {
std::is_same<btree_iterator<N, R, P>, const_iterator>::value && std::is_same<btree_iterator<N, R, P>, const_iterator>::value &&
std::is_same<btree_iterator, iterator>::value, std::is_same<btree_iterator, iterator>::value,
int> = 0> int> = 0>
explicit btree_iterator(const btree_iterator<N, R, P> &other) explicit btree_iterator(const btree_iterator<N, R, P> other)
: node(const_cast<node_type *>(other.node)), position(other.position) {} : node(const_cast<node_type *>(other.node)), position(other.position) {}
// Increment/decrement the iterator. // Increment/decrement the iterator.
...@@ -1022,6 +1022,8 @@ struct btree_iterator { ...@@ -1022,6 +1022,8 @@ struct btree_iterator {
} }
private: private:
friend iterator;
friend const_iterator;
template <typename Params> template <typename Params>
friend class btree; friend class btree;
template <typename Tree> template <typename Tree>
...@@ -1032,8 +1034,6 @@ struct btree_iterator { ...@@ -1032,8 +1034,6 @@ struct btree_iterator {
friend class btree_map_container; friend class btree_map_container;
template <typename Tree> template <typename Tree>
friend class btree_multiset_container; friend class btree_multiset_container;
template <typename N, typename R, typename P>
friend struct btree_iterator;
template <typename TreeType, typename CheckerType> template <typename TreeType, typename CheckerType>
friend class base_checker; friend class base_checker;
...@@ -1122,7 +1122,8 @@ class btree { ...@@ -1122,7 +1122,8 @@ class btree {
using const_reference = typename Params::const_reference; using const_reference = typename Params::const_reference;
using pointer = typename Params::pointer; using pointer = typename Params::pointer;
using const_pointer = typename Params::const_pointer; using const_pointer = typename Params::const_pointer;
using iterator = btree_iterator<node_type, reference, pointer>; using iterator =
typename btree_iterator<node_type, reference, pointer>::iterator;
using const_iterator = typename iterator::const_iterator; using const_iterator = typename iterator::const_iterator;
using reverse_iterator = std::reverse_iterator<iterator>; using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>; using const_reverse_iterator = std::reverse_iterator<const_iterator>;
...@@ -1135,7 +1136,11 @@ class btree { ...@@ -1135,7 +1136,11 @@ class btree {
private: private:
// For use in copy_or_move_values_in_order. // For use in copy_or_move_values_in_order.
const value_type &maybe_move_from_iterator(const_iterator it) { return *it; } const value_type &maybe_move_from_iterator(const_iterator it) { return *it; }
value_type &&maybe_move_from_iterator(iterator it) { return std::move(*it); } value_type &&maybe_move_from_iterator(iterator it) {
// This is a destructive operation on the other container so it's safe for
// us to const_cast and move from the keys here even if it's a set.
return std::move(const_cast<value_type &>(*it));
}
// Copies or moves (depending on the template parameter) the values in // Copies or moves (depending on the template parameter) the values in
// other into this btree in their order in other. This btree must be empty // other into this btree in their order in other. This btree must be empty
......
...@@ -19,19 +19,22 @@ ...@@ -19,19 +19,22 @@
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
bool EqualsIgnoreCase(absl::string_view piece1, absl::string_view piece2) { bool EqualsIgnoreCase(absl::string_view piece1,
absl::string_view piece2) noexcept {
return (piece1.size() == piece2.size() && return (piece1.size() == piece2.size() &&
0 == absl::strings_internal::memcasecmp(piece1.data(), piece2.data(), 0 == absl::strings_internal::memcasecmp(piece1.data(), piece2.data(),
piece1.size())); piece1.size()));
// memcasecmp uses absl::ascii_tolower(). // memcasecmp uses absl::ascii_tolower().
} }
bool StartsWithIgnoreCase(absl::string_view text, absl::string_view prefix) { bool StartsWithIgnoreCase(absl::string_view text,
absl::string_view prefix) noexcept {
return (text.size() >= prefix.size()) && return (text.size() >= prefix.size()) &&
EqualsIgnoreCase(text.substr(0, prefix.size()), prefix); EqualsIgnoreCase(text.substr(0, prefix.size()), prefix);
} }
bool EndsWithIgnoreCase(absl::string_view text, absl::string_view suffix) { bool EndsWithIgnoreCase(absl::string_view text,
absl::string_view suffix) noexcept {
return (text.size() >= suffix.size()) && return (text.size() >= suffix.size()) &&
EqualsIgnoreCase(text.substr(text.size() - suffix.size()), suffix); EqualsIgnoreCase(text.substr(text.size() - suffix.size()), suffix);
} }
......
...@@ -43,14 +43,16 @@ ABSL_NAMESPACE_BEGIN ...@@ -43,14 +43,16 @@ ABSL_NAMESPACE_BEGIN
// StrContains() // StrContains()
// //
// Returns whether a given string `haystack` contains the substring `needle`. // Returns whether a given string `haystack` contains the substring `needle`.
inline bool StrContains(absl::string_view haystack, absl::string_view needle) { inline bool StrContains(absl::string_view haystack,
absl::string_view needle) noexcept {
return haystack.find(needle, 0) != haystack.npos; return haystack.find(needle, 0) != haystack.npos;
} }
// StartsWith() // StartsWith()
// //
// Returns whether a given string `text` begins with `prefix`. // Returns whether a given string `text` begins with `prefix`.
inline bool StartsWith(absl::string_view text, absl::string_view prefix) { inline bool StartsWith(absl::string_view text,
absl::string_view prefix) noexcept {
return prefix.empty() || return prefix.empty() ||
(text.size() >= prefix.size() && (text.size() >= prefix.size() &&
memcmp(text.data(), prefix.data(), prefix.size()) == 0); memcmp(text.data(), prefix.data(), prefix.size()) == 0);
...@@ -59,7 +61,8 @@ inline bool StartsWith(absl::string_view text, absl::string_view prefix) { ...@@ -59,7 +61,8 @@ inline bool StartsWith(absl::string_view text, absl::string_view prefix) {
// EndsWith() // EndsWith()
// //
// Returns whether a given string `text` ends with `suffix`. // Returns whether a given string `text` ends with `suffix`.
inline bool EndsWith(absl::string_view text, absl::string_view suffix) { inline bool EndsWith(absl::string_view text,
absl::string_view suffix) noexcept {
return suffix.empty() || return suffix.empty() ||
(text.size() >= suffix.size() && (text.size() >= suffix.size() &&
memcmp(text.data() + (text.size() - suffix.size()), suffix.data(), memcmp(text.data() + (text.size() - suffix.size()), suffix.data(),
...@@ -70,19 +73,22 @@ inline bool EndsWith(absl::string_view text, absl::string_view suffix) { ...@@ -70,19 +73,22 @@ inline bool EndsWith(absl::string_view text, absl::string_view suffix) {
// //
// Returns whether given ASCII strings `piece1` and `piece2` are equal, ignoring // Returns whether given ASCII strings `piece1` and `piece2` are equal, ignoring
// case in the comparison. // case in the comparison.
bool EqualsIgnoreCase(absl::string_view piece1, absl::string_view piece2); bool EqualsIgnoreCase(absl::string_view piece1,
absl::string_view piece2) noexcept;
// StartsWithIgnoreCase() // StartsWithIgnoreCase()
// //
// Returns whether a given ASCII string `text` starts with `prefix`, // Returns whether a given ASCII string `text` starts with `prefix`,
// ignoring case in the comparison. // ignoring case in the comparison.
bool StartsWithIgnoreCase(absl::string_view text, absl::string_view prefix); bool StartsWithIgnoreCase(absl::string_view text,
absl::string_view prefix) noexcept;
// EndsWithIgnoreCase() // EndsWithIgnoreCase()
// //
// Returns whether a given ASCII string `text` ends with `suffix`, ignoring // Returns whether a given ASCII string `text` ends with `suffix`, ignoring
// case in the comparison. // case in the comparison.
bool EndsWithIgnoreCase(absl::string_view text, absl::string_view suffix); bool EndsWithIgnoreCase(absl::string_view text,
absl::string_view suffix) noexcept;
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment