Commit 35e8e3f7 by Martijn Vels Committed by Copybara-Service

Make `SanitizerSafeCopy()` constexpr, and check for constant evaluation

PiperOrigin-RevId: 504728034
Change-Id: Ifb338247b7484426e25a58580783a1d70d27e6fd
parent a69b0ae5
...@@ -768,18 +768,22 @@ class InlineData { ...@@ -768,18 +768,22 @@ class InlineData {
} }
#ifdef ABSL_INTERNAL_CORD_HAVE_SANITIZER #ifdef ABSL_INTERNAL_CORD_HAVE_SANITIZER
Rep SanitizerSafeCopy() const { constexpr Rep SanitizerSafeCopy() const {
Rep res; if (!absl::is_constant_evaluated()) {
if (is_tree()) { Rep res;
res = *this; if (is_tree()) {
res = *this;
} else {
res.set_tag(tag());
memcpy(res.as_chars(), as_chars(), inline_size());
}
return res;
} else { } else {
res.set_tag(tag()); return *this;
memcpy(res.as_chars(), as_chars(), inline_size());
} }
return res;
} }
#else #else
const Rep& SanitizerSafeCopy() const { return *this; } constexpr const Rep& SanitizerSafeCopy() const { return *this; }
#endif #endif
// If the data has length <= kMaxInline, we store it in `data`, and // If the data has length <= kMaxInline, we store it in `data`, and
......
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