summaryrefslogtreecommitdiff
path: root/absl/strings
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-11-05 10:55:22 -0800
committerGravatar Andy Getz <durandal@google.com>2020-11-05 14:17:56 -0500
commite96d49687d9c078f2d47356b6723c3b5715493f7 (patch)
treecc884fdd720693ff90ae7ebe1ab0ef06f663c521 /absl/strings
parent731852f10b737c5a5c3be93777a2c17b24b4c5a6 (diff)
Export of internal Abseil changes
-- 76c5eb1cf346a1a64e0a5e2edf032546d600075a by Andy Getzendanner <durandal@google.com>: Fix stacktrace on aarch64 architecture. Fixes #805 Import of https://github.com/abseil/abseil-cpp/pull/827 PiperOrigin-RevId: 340886173 -- 28f48f7bcadd4681854cddb0a7736d26d7dab000 by Andy Getzendanner <durandal@google.com>: Some attribute cleanups in and around statusor: * mark statusor_internal::Helper::Crash ABSL_ATTRIBUTE_NORETURN * add ABSL_INTERNAL_UNREACHABLE to ABSL_INTERNAL_LOG when severity is FATAL * create ABSL_INTERNAL_UNREACHABLE to wrap __builtin_unreachable and __assume(0) * use ABSL_ATTRIBUTE_NONNULL instead of __builtin_unreachable in statusor_internal::PlacementNew (https://godbolt.org/z/n691fa) PiperOrigin-RevId: 340868438 -- 33905d1d2d01eb6f81b04abaf24170bfebb6df09 by Andy Getzendanner <durandal@google.com>: moved deleted functions to public for better compiler errors. Import of https://github.com/abseil/abseil-cpp/pull/828 PiperOrigin-RevId: 340863976 -- 5e502222dfc3f5a0ef146535a9e16c743b005092 by Jorg Brown <jorg@google.com>: ConvertibleToStringView wastes a lot of cycles initializing members just to reset them immediately after. Only initialize the string storage when needed. This makes StrSplit() 0-30% faster depending on the use case. PiperOrigin-RevId: 340732039 GitOrigin-RevId: 76c5eb1cf346a1a64e0a5e2edf032546d600075a Change-Id: I2ba1f717c4eaad384cd0a22694fd05f9e6a2d8fa
Diffstat (limited to 'absl/strings')
-rw-r--r--absl/strings/internal/str_split_internal.h51
1 files changed, 18 insertions, 33 deletions
diff --git a/absl/strings/internal/str_split_internal.h b/absl/strings/internal/str_split_internal.h
index 76924771..49ec5392 100644
--- a/absl/strings/internal/str_split_internal.h
+++ b/absl/strings/internal/str_split_internal.h
@@ -66,56 +66,41 @@ class ConvertibleToStringView {
// Matches rvalue strings and moves their data to a member.
ConvertibleToStringView(std::string&& s) // NOLINT(runtime/explicit)
- : copy_(std::move(s)), value_(copy_), self_referential_(true) {}
+ : copy_(std::move(s)), value_(copy_) {}
ConvertibleToStringView(const ConvertibleToStringView& other)
- : value_(other.value_), self_referential_(other.self_referential_) {
- if (other.self_referential_) {
- new (&copy_) std::string(other.copy_);
- value_ = copy_;
- }
- }
+ : copy_(other.copy_),
+ value_(other.IsSelfReferential() ? copy_ : other.value_) {}
- ConvertibleToStringView(ConvertibleToStringView&& other)
- : value_(other.value_), self_referential_(other.self_referential_) {
- if (other.self_referential_) {
- new (&copy_) std::string(std::move(other.copy_));
- value_ = copy_;
- }
+ ConvertibleToStringView(ConvertibleToStringView&& other) {
+ StealMembers(std::move(other));
}
ConvertibleToStringView& operator=(ConvertibleToStringView other) {
- this->~ConvertibleToStringView();
- new (this) ConvertibleToStringView(std::move(other));
+ StealMembers(std::move(other));
return *this;
}
absl::string_view value() const { return value_; }
- ~ConvertibleToStringView() { MaybeReleaseCopy(); }
-
private:
- void MaybeReleaseCopy() {
- if (self_referential_) {
- // An explicit destructor call cannot be a qualified name such as
- // std::string. The "using" declaration works around this
- // issue by creating an unqualified name for the destructor.
- using string_type = std::string;
- copy_.~string_type();
+ // Returns true if ctsp's value refers to its internal copy_ member.
+ bool IsSelfReferential() const { return value_.data() == copy_.data(); }
+
+ void StealMembers(ConvertibleToStringView&& other) {
+ if (other.IsSelfReferential()) {
+ copy_ = std::move(other.copy_);
+ value_ = copy_;
+ other.value_ = other.copy_;
+ } else {
+ value_ = other.value_;
}
}
- struct Unused { // MSVC disallows unions with only 1 member.
- };
+
// Holds the data moved from temporary std::string arguments. Declared first
// so that 'value' can refer to 'copy_'.
- union {
- std::string copy_;
- Unused unused_;
- };
-
+ std::string copy_;
absl::string_view value_;
- // true if value_ refers to the internal copy_ member.
- bool self_referential_ = false;
};
// An iterator that enumerates the parts of a string from a Splitter. The text