Aggressively pipeline branches that have Arenas for performance.
PiperOrigin-RevId: 494917475
diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h
index b60b7d0..8a7d1b4 100644
--- a/src/google/protobuf/arena.h
+++ b/src/google/protobuf/arena.h
@@ -271,7 +271,7 @@
// is obtained from the arena).
template <typename T, typename... Args>
PROTOBUF_NDEBUG_INLINE static T* Create(Arena* arena, Args&&... args) {
- if (arena == nullptr) {
+ if (PROTOBUF_PREDICT_FALSE(arena == nullptr)) {
return new T(std::forward<Args>(args)...);
}
auto destructor =
@@ -320,10 +320,13 @@
"CreateArray requires a trivially destructible type");
GOOGLE_ABSL_CHECK_LE(num_elements, std::numeric_limits<size_t>::max() / sizeof(T))
<< "Requested size is too large to fit into size_t.";
- if (arena == nullptr) {
+ if (PROTOBUF_PREDICT_FALSE(arena == nullptr)) {
return static_cast<T*>(::operator new[](num_elements * sizeof(T)));
} else {
- return arena->CreateInternalRawArray<T>(num_elements);
+ // We count on compiler to realize that if sizeof(T) is a multiple of
+ // 8 AlignUpTo can be elided.
+ return static_cast<T*>(
+ arena->AllocateAlignedForArray(sizeof(T) * num_elements, alignof(T)));
}
}
@@ -598,18 +601,6 @@
std::forward<Args>(args)...);
}
- // Just allocate the required size for the given type assuming the
- // type has a trivial constructor.
- template <typename T>
- PROTOBUF_NDEBUG_INLINE T* CreateInternalRawArray(size_t num_elements) {
- GOOGLE_ABSL_CHECK_LE(num_elements, std::numeric_limits<size_t>::max() / sizeof(T))
- << "Requested size is too large to fit into size_t.";
- // We count on compiler to realize that if sizeof(T) is a multiple of
- // 8 AlignUpTo can be elided.
- const size_t n = sizeof(T) * num_elements;
- return static_cast<T*>(AllocateAlignedForArray(n, alignof(T)));
- }
-
template <typename T, typename... Args>
PROTOBUF_NDEBUG_INLINE T* DoCreateMessage(Args&&... args) {
return InternalHelper<T>::Construct(