Skip to content

Commit

Permalink
Reduce the required alignment of ArenaString from 8 to 4 (#10298)
Browse files Browse the repository at this point in the history
  • Loading branch information
yashykt committed Jul 25, 2022
1 parent ddb21b2 commit c254825
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/google/protobuf/arenastring.cc
Expand Up @@ -50,7 +50,8 @@ namespace internal {

namespace {

// Enforce that allocated data aligns to at least 8 bytes, and that
// TaggedStringPtr::Flags uses the lower 2 bits as tags.
// Enforce that allocated data aligns to at least 4 bytes, and that
// the alignment of the global const string value does as well.
// The alignment guaranteed by `new std::string` depends on both:
// - new align = __STDCPP_DEFAULT_NEW_ALIGNMENT__ / max_align_t
Expand All @@ -64,8 +65,8 @@ constexpr size_t kNewAlign = alignof(std::max_align_t);
#endif
constexpr size_t kStringAlign = alignof(std::string);

static_assert((kStringAlign > kNewAlign ? kStringAlign : kNewAlign) >= 8, "");
static_assert(alignof(ExplicitlyConstructedArenaString) >= 8, "");
static_assert((kStringAlign > kNewAlign ? kStringAlign : kNewAlign) >= 4, "");
static_assert(alignof(ExplicitlyConstructedArenaString) >= 4, "");

} // namespace

Expand Down

0 comments on commit c254825

Please sign in to comment.