Fix QuicOneBlockArena for Windows This CL does not change any behavior (apart from fixing a linker failure in Chrome). PiperOrigin-RevId: 345734394 Change-Id: I975621086cd30777f85639725b4a863dbaca251f
diff --git a/quic/core/quic_one_block_arena.h b/quic/core/quic_one_block_arena.h index 15c0a99..ada5cd3 100644 --- a/quic/core/quic_one_block_arena.h +++ b/quic/core/quic_one_block_arena.h
@@ -24,7 +24,7 @@ static const uint32_t kMaxAlign = 8; public: - QuicOneBlockArena(); + QuicOneBlockArena() : offset_(0) {} QuicOneBlockArena(const QuicOneBlockArena&) = delete; QuicOneBlockArena& operator=(const QuicOneBlockArena&) = delete; @@ -32,7 +32,24 @@ // forwarded to |T|'s constructor. The returned pointer's lifetime is // controlled by QuicArenaScopedPtr. template <typename T, typename... Args> - QuicArenaScopedPtr<T> New(Args&&... args); + QuicArenaScopedPtr<T> New(Args&&... args) { + DCHECK_LT(AlignedSize<T>(), ArenaSize) + << "Object is too large for the arena."; + static_assert(alignof(T) > 1, + "Objects added to the arena must be at least 2B aligned."); + if (QUIC_PREDICT_FALSE(offset_ > ArenaSize - AlignedSize<T>())) { + QUIC_BUG << "Ran out of space in QuicOneBlockArena at " << this + << ", max size was " << ArenaSize << ", failing request was " + << AlignedSize<T>() << ", end of arena was " << offset_; + return QuicArenaScopedPtr<T>(new T(std::forward<Args>(args)...)); + } + + void* buf = &storage_[offset_]; + new (buf) T(std::forward<Args>(args)...); + offset_ += AlignedSize<T>(); + return QuicArenaScopedPtr<T>(buf, + QuicArenaScopedPtr<T>::ConstructFrom::kArena); + } private: // Returns the size of |T| aligned up to |kMaxAlign|. @@ -49,30 +66,6 @@ uint32_t offset_; }; -template <uint32_t ArenaSize> -QuicOneBlockArena<ArenaSize>::QuicOneBlockArena() : offset_(0) {} - -template <uint32_t ArenaSize> -template <typename T, typename... Args> -QuicArenaScopedPtr<T> QuicOneBlockArena<ArenaSize>::New(Args&&... args) { - DCHECK_LT(AlignedSize<T>(), ArenaSize) - << "Object is too large for the arena."; - static_assert(alignof(T) > 1, - "Objects added to the arena must be at least 2B aligned."); - if (QUIC_PREDICT_FALSE(offset_ > ArenaSize - AlignedSize<T>())) { - QUIC_BUG << "Ran out of space in QuicOneBlockArena at " << this - << ", max size was " << ArenaSize << ", failing request was " - << AlignedSize<T>() << ", end of arena was " << offset_; - return QuicArenaScopedPtr<T>(new T(std::forward<Args>(args)...)); - } - - void* buf = &storage_[offset_]; - new (buf) T(std::forward<Args>(args)...); - offset_ += AlignedSize<T>(); - return QuicArenaScopedPtr<T>(buf, - QuicArenaScopedPtr<T>::ConstructFrom::kArena); -} - // QuicConnections currently use around 1KB of polymorphic types which would // ordinarily be on the heap. Instead, store them inline in an arena. using QuicConnectionArena = QuicOneBlockArena<1056>;