[libcxx-commits] [libcxx] [llvm] [libc++] Remove `get_temporary_buffer`/`return_temporary_buffer` (PR #100914)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 28 05:58:38 PDT 2024
================
@@ -0,0 +1,122 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MEMORY_SCOPED_TEMPORARY_BUFFER_H
+#define _LIBCPP___MEMORY_SCOPED_TEMPORARY_BUFFER_H
+
+#include <__config>
+#include <__memory/allocator.h>
+#include <__type_traits/is_constant_evaluated.h>
+#include <cstddef>
+#include <new>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+struct __temporary_allocation_result {
+ _Tp* __ptr;
+ ptrdiff_t __count;
+};
+
+template <class _Tp>
+class __scoped_temporary_buffer {
+public:
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __scoped_temporary_buffer() _NOEXCEPT
+ : __ptr_(NULL),
+ __count_(0) {}
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __scoped_temporary_buffer(ptrdiff_t __count) _NOEXCEPT
+ : __ptr_(NULL),
+ __count_(0) {
+ __try_allocate(__count);
+ }
+
+ // This constructor is only needed to implement get_temporary_buffer().
+ // pre: __buf_ptr points to the beginning of a previously allocated scoped temporary buffer or is null
+ // notes: __count_ is ignored in non-constant evaluation
+ _LIBCPP_HIDE_FROM_ABI explicit __scoped_temporary_buffer(_Tp* __buf_ptr) _NOEXCEPT : __ptr_(__buf_ptr), __count_(0) {}
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__scoped_temporary_buffer() _NOEXCEPT {
+ if (__libcpp_is_constant_evaluated()) {
+ if (__ptr_)
+ allocator<_Tp>().deallocate(__ptr_, __count_);
+ return;
+ }
+
+ std::__libcpp_deallocate_unsized((void*)__ptr_, _LIBCPP_ALIGNOF(_Tp));
----------------
ldionne wrote:
This was just copied from the old code. I think we can refactor this quite a bit, but I would tackle that as a follow-up patch.
https://github.com/llvm/llvm-project/pull/100914
More information about the libcxx-commits
mailing list