diff options
author | yazevnul <yazevnul@yandex-team.ru> | 2022-02-10 16:46:46 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:46 +0300 |
commit | 8cbc307de0221f84c80c42dcbe07d40727537e2c (patch) | |
tree | 625d5a673015d1df891e051033e9fcde5c7be4e5 /util/memory/segmented_string_pool.h | |
parent | 30d1ef3941e0dc835be7609de5ebee66958f215a (diff) | |
download | ydb-8cbc307de0221f84c80c42dcbe07d40727537e2c.tar.gz |
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/memory/segmented_string_pool.h')
-rw-r--r-- | util/memory/segmented_string_pool.h | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/util/memory/segmented_string_pool.h b/util/memory/segmented_string_pool.h index a40aa408f5..ecc3ca3c1a 100644 --- a/util/memory/segmented_string_pool.h +++ b/util/memory/segmented_string_pool.h @@ -23,7 +23,7 @@ protected: size_t _size; // size of allocated chunk in sizeof(T)-units size_t freepos; // offset to free chunk's memory in bytes seg_inf() - : data(nullptr) + : data(nullptr) , _size(0) , freepos(0) { @@ -46,23 +46,23 @@ protected: const char* Name; // for debug memory usage protected: void check_capacity(size_t len) { - if (Y_UNLIKELY(!last_free || len > last_free)) { + if (Y_UNLIKELY(!last_free || len > last_free)) { if (curseg != segs.end() && curseg->freepos > 0) ++curseg; last_free = (len > segment_size ? len : segment_size); if (curseg == segs.end() || curseg->_size < last_free) { segs.push_back(seg_inf(seg_allocator.allocate(last_free), last_free)); - if (Y_UNLIKELY(Name)) + if (Y_UNLIKELY(Name)) printf("Pool \"%s\" was increased by %" PRISZT " bytes to %" PRISZT " Mb.\n", Name, last_free * sizeof(T), capacity() / 0x100000); curseg = segs.end() - 1; } - Y_ASSERT(curseg->freepos == 0); - Y_ASSERT(curseg->_size >= last_free); + Y_ASSERT(curseg->freepos == 0); + Y_ASSERT(curseg->_size >= last_free); } } public: - explicit segmented_pool(size_t segsz, const char* name = nullptr) + explicit segmented_pool(size_t segsz, const char* name = nullptr) : segment_size(segsz) , last_free(0) , last_ins_size(0) @@ -131,18 +131,18 @@ public: last_ins_size = 0; } void undo_last_append() { - Y_ASSERT(curseg != segs.end()); // do not use before append() + Y_ASSERT(curseg != segs.end()); // do not use before append() if (last_ins_size) { - Y_ASSERT(last_ins_size <= curseg->freepos); + Y_ASSERT(last_ins_size <= curseg->freepos); curseg->freepos -= last_ins_size; last_free += last_ins_size / sizeof(T); last_ins_size = 0; } } void alloc_first_seg() { - Y_ASSERT(capacity() == 0); + Y_ASSERT(capacity() == 0); check_capacity(segment_size); - Y_ASSERT(capacity() == segment_size * sizeof(T)); + Y_ASSERT(capacity() == segment_size * sizeof(T)); } }; @@ -151,27 +151,27 @@ private: using _Base = segmented_pool<char>; public: - segmented_string_pool() - : segmented_string_pool(1024 * 1024) - { - } - - explicit segmented_string_pool(size_t segsz) + segmented_string_pool() + : segmented_string_pool(1024 * 1024) + { + } + + explicit segmented_string_pool(size_t segsz) : _Base(segsz) { } char* append(const char* src) { - Y_ASSERT(src); + Y_ASSERT(src); return _Base::append(src, strlen(src) + 1); } char* append(const char* src, size_t len) { - char* rv = _Base::append(nullptr, len + 1); + char* rv = _Base::append(nullptr, len + 1); if (src) memcpy(rv, src, len); rv[len] = 0; return rv; } - char* Append(const TStringBuf s) { + char* Append(const TStringBuf s) { return append(s.data(), s.size()); } void align_4() { @@ -180,7 +180,7 @@ public: curseg->freepos = t; } char* Allocate(size_t len) { - return append(nullptr, len); + return append(nullptr, len); } }; |