summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
authorGravatar Martijn Vels <mvels@google.com>2023-01-25 19:57:34 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-01-25 19:58:21 -0800
commit35e8e3f7a2c6972d4c591448e8bbe4f9ed9f815a (patch)
treef8e1aab380163cf5bec3f266b8c384d4f46c8b7b /absl
parenta69b0ae5cdba53a45617afc408618a3e1ac244de (diff)
Make `SanitizerSafeCopy()` constexpr, and check for constant evaluation
PiperOrigin-RevId: 504728034 Change-Id: Ifb338247b7484426e25a58580783a1d70d27e6fd
Diffstat (limited to 'absl')
-rw-r--r--absl/strings/internal/cord_internal.h20
1 files changed, 12 insertions, 8 deletions
diff --git a/absl/strings/internal/cord_internal.h b/absl/strings/internal/cord_internal.h
index 63a81f4f..e6f0d544 100644
--- a/absl/strings/internal/cord_internal.h
+++ b/absl/strings/internal/cord_internal.h
@@ -768,18 +768,22 @@ class InlineData {
}
#ifdef ABSL_INTERNAL_CORD_HAVE_SANITIZER
- Rep SanitizerSafeCopy() const {
- Rep res;
- if (is_tree()) {
- res = *this;
+ constexpr Rep SanitizerSafeCopy() const {
+ if (!absl::is_constant_evaluated()) {
+ Rep res;
+ if (is_tree()) {
+ res = *this;
+ } else {
+ res.set_tag(tag());
+ memcpy(res.as_chars(), as_chars(), inline_size());
+ }
+ return res;
} else {
- res.set_tag(tag());
- memcpy(res.as_chars(), as_chars(), inline_size());
+ return *this;
}
- return res;
}
#else
- const Rep& SanitizerSafeCopy() const { return *this; }
+ constexpr const Rep& SanitizerSafeCopy() const { return *this; }
#endif
// If the data has length <= kMaxInline, we store it in `data`, and