File tree Expand file tree Collapse file tree 2 files changed +4
-47
lines changed Expand file tree Collapse file tree 2 files changed +4
-47
lines changed Original file line number Diff line number Diff line change 2222
2323#include < cxx/cxx_fwd.h>
2424
25- #include < cstddef>
26- #include < cstdint>
27- #include < cstdlib>
25+ #include < memory_resource>
2826#include < new>
29- #include < vector>
3027
3128namespace cxx {
3229
33- class Arena {
34- struct Block {
35- static const std::size_t SIZE = 16 * 1024 ;
36-
37- char * data;
38- char * ptr;
39-
40- Block (const Block&) = delete ;
41- auto operator =(const Block&) -> Block& = delete ;
42-
43- Block () { ptr = data = static_cast <char *>(std::malloc (SIZE)); }
44-
45- ~Block () {
46- if (data) std::free (data);
47- }
48- };
49-
50- std::vector<Block*> blocks;
51-
30+ class Arena : public std ::pmr::monotonic_buffer_resource {
5231 public:
53- Arena (const Arena& other) = delete ;
54- auto operator =(const Arena& other) -> Arena& = delete ;
55- Arena () = default ;
56- ~Arena () { reset (); }
57-
58- void reset () {
59- for (auto && block : blocks) delete block;
60- blocks.clear ();
61- }
62-
63- auto allocate (std::size_t size) noexcept -> void* {
64- if (!blocks.empty ()) {
65- constexpr auto align = alignof (std::max_align_t ) - 1 ;
66-
67- auto block = blocks.back ();
68- block->ptr = (char *)((std::intptr_t (block->ptr ) + align) & ~align);
69- void * addr = block->ptr ;
70- block->ptr += size;
71- if (block->ptr < block->data + Block::SIZE) return addr;
72- }
73- blocks.push_back (::new Block ());
74- return allocate (size);
75- }
32+ using monotonic_buffer_resource::monotonic_buffer_resource;
7633};
7734
7835struct Managed {
Original file line number Diff line number Diff line change @@ -2966,7 +2966,7 @@ void Preprocessor::setOnWillIncludeHeader(
29662966 d->willIncludeHeader_ = std::move (willIncludeHeader);
29672967}
29682968
2969- void Preprocessor::squeeze () { d->pool_ .reset (); }
2969+ void Preprocessor::squeeze () { d->pool_ .release (); }
29702970
29712971auto Preprocessor::sourceFileName (uint32_t sourceFileId) const
29722972 -> const std::string & {
You can’t perform that action at this time.
0 commit comments