[libcxx-commits] [libcxx] [libc++] Refactor some code in monotonic_buffer_resource (PR #117271)
Peng Xie via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Dec 1 18:20:52 PST 2024
================
@@ -429,23 +429,18 @@ static void* align_down(size_t align, size_t size, void*& ptr, size_t& space) {
return ptr;
}
-void* monotonic_buffer_resource::__initial_descriptor::__try_allocate_from_chunk(size_t bytes, size_t align) {
- if (!__cur_)
- return nullptr;
- void* new_ptr = static_cast<void*>(__cur_);
- size_t new_capacity = (__cur_ - __start_);
- void* aligned_ptr = align_down(align, bytes, new_ptr, new_capacity);
- if (aligned_ptr != nullptr)
- __cur_ = static_cast<char*>(new_ptr);
- return aligned_ptr;
-}
-
-void* monotonic_buffer_resource::__chunk_footer::__try_allocate_from_chunk(size_t bytes, size_t align) {
- void* new_ptr = static_cast<void*>(__cur_);
- size_t new_capacity = (__cur_ - __start_);
+template <bool is_initial, typename Chunk>
+void* __try_allocate_from_chunk(Chunk& self, size_t bytes, size_t align) {
+ if constexpr (is_initial) {
+ // here only for __initial_descriptor
----------------
love1angel wrote:
done
https://github.com/llvm/llvm-project/pull/117271
More information about the libcxx-commits
mailing list