mirror of
https://github.com/diamante0018/BlackOpsPlugin.git
synced 2025-05-10 14:24:50 +00:00
maint(string): update
This commit is contained in:
parent
38398db5e9
commit
c80d70c698
@ -7,7 +7,7 @@
|
||||
|
||||
namespace utils::string {
|
||||
const char* va(const char* fmt, ...) {
|
||||
static thread_local va_provider<8, 256> provider;
|
||||
static thread_local va_provider<8, 1024> provider;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
@ -6,10 +6,10 @@ template <class Type, size_t n> size_t ARRAYSIZE(Type (&)[n]) { return n; }
|
||||
#endif
|
||||
|
||||
namespace utils::string {
|
||||
template <size_t Buffers, size_t MinBufferSize> class va_provider final {
|
||||
template <size_t buffers, size_t min_buffer_size> class va_provider final {
|
||||
public:
|
||||
static_assert(Buffers != 0 && MinBufferSize != 0,
|
||||
"Buffers and MinBufferSize mustn't be 0");
|
||||
static_assert(buffers != 0 && min_buffer_size != 0,
|
||||
"buffers and min_buffer_size mustn't be 0");
|
||||
|
||||
va_provider() : current_buffer_(0) {}
|
||||
|
||||
@ -17,13 +17,13 @@ public:
|
||||
++this->current_buffer_ %= ARRAYSIZE(this->string_pool_);
|
||||
auto entry = &this->string_pool_[this->current_buffer_];
|
||||
|
||||
if (!entry->size || !entry->buffer) {
|
||||
if (!entry->size_ || !entry->buffer_) {
|
||||
throw std::runtime_error("String pool not initialized");
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const int res =
|
||||
vsnprintf_s(entry->buffer, entry->size, _TRUNCATE, format, ap);
|
||||
vsnprintf_s(entry->buffer_, entry->size_, _TRUNCATE, format, ap);
|
||||
if (res > 0)
|
||||
break; // Success
|
||||
if (res == 0)
|
||||
@ -38,34 +38,34 @@ public:
|
||||
private:
|
||||
class entry final {
|
||||
public:
|
||||
explicit entry(const size_t _size = MinBufferSize)
|
||||
: size(_size), buffer(nullptr) {
|
||||
if (this->size < MinBufferSize)
|
||||
this->size = MinBufferSize;
|
||||
explicit entry(const size_t size = min_buffer_size)
|
||||
: size(size), buffer_(nullptr) {
|
||||
if (this->size_ < min_buffer_size)
|
||||
this->size_ = min_buffer_size;
|
||||
this->allocate();
|
||||
}
|
||||
|
||||
~entry() {
|
||||
if (this->buffer)
|
||||
memory::get_allocator()->free(this->buffer);
|
||||
this->size = 0;
|
||||
this->buffer = nullptr;
|
||||
if (this->buffer_)
|
||||
memory::get_allocator()->free(this->buffer_);
|
||||
this->size_ = 0;
|
||||
this->buffer_ = nullptr;
|
||||
}
|
||||
|
||||
void allocate() {
|
||||
if (this->buffer)
|
||||
memory::get_allocator()->free(this->buffer);
|
||||
this->buffer =
|
||||
memory::get_allocator()->allocate_array<char>(this->size + 1);
|
||||
if (this->buffer_)
|
||||
memory::get_allocator()->free(this->buffer_);
|
||||
this->buffer_ =
|
||||
memory::get_allocator()->allocate_array<char>(this->size_ + 1);
|
||||
}
|
||||
|
||||
void double_size() {
|
||||
this->size *= 2;
|
||||
this->size_ *= 2;
|
||||
this->allocate();
|
||||
}
|
||||
|
||||
size_t size;
|
||||
char* buffer;
|
||||
size_t size_;
|
||||
char* buffer_;
|
||||
};
|
||||
|
||||
size_t current_buffer_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user