Skip to content

Commit

Permalink
Make SanitizerSafeCopy() constexpr, and check for constant evaluation
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 504728034
Change-Id: Ifb338247b7484426e25a58580783a1d70d27e6fd
  • Loading branch information
martijnvels authored and copybara-github committed Jan 26, 2023
1 parent a69b0ae commit 35e8e3f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions absl/strings/internal/cord_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35e8e3f

Please sign in to comment.