| 28 | using TBlock = IAllocator::TBlock; |
| 29 | |
| 30 | class TChunk: public TIntrusiveListItem<TChunk> { |
| 31 | public: |
| 32 | inline TChunk(size_t len = 0) noexcept |
| 33 | : Cur_((char*)(this + 1)) |
| 34 | , Left_(len) |
| 35 | { |
| 36 | Y_ASSERT((((size_t)Cur_) % PLATFORM_DATA_ALIGN) == 0); |
| 37 | } |
| 38 | |
| 39 | inline void* Allocate(size_t len) noexcept { |
| 40 | if (Left_ >= len) { |
| 41 | char* ret = Cur_; |
| 42 | |
| 43 | Cur_ += len; |
| 44 | Left_ -= len; |
| 45 | |
| 46 | return ret; |
| 47 | } |
| 48 | |
| 49 | return nullptr; |
| 50 | } |
| 51 | |
| 52 | inline void* Allocate(size_t len, size_t align) noexcept { |
| 53 | size_t pad = AlignUp(Cur_, align) - Cur_; |
| 54 | |
| 55 | void* ret = Allocate(pad + len); |
| 56 | if (ret) { |
| 57 | return static_cast<char*>(ret) + pad; |
| 58 | } |
| 59 | |
| 60 | return nullptr; |
| 61 | } |
| 62 | |
| 63 | inline size_t BlockLength() const noexcept { |
| 64 | return (Cur_ + Left_) - (char*)this; |
| 65 | } |
| 66 | |
| 67 | inline size_t Used() const noexcept { |
| 68 | return Cur_ - (const char*)this; |
| 69 | } |
| 70 | |
| 71 | inline size_t Left() const noexcept { |
| 72 | return Left_; |
| 73 | } |
| 74 | |
| 75 | inline const char* Data() const noexcept { |
| 76 | return (const char*)(this + 1); |
| 77 | } |
| 78 | |
| 79 | inline char* Data() noexcept { |
| 80 | return (char*)(this + 1); |
| 81 | } |
| 82 | |
| 83 | inline size_t DataSize() const noexcept { |
| 84 | return Cur_ - Data(); |
| 85 | } |
| 86 | |
| 87 | inline void ResetChunk() noexcept { |
no outgoing calls
no test coverage detected