summaryrefslogtreecommitdiff
path: root/zen/string_base.h
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-10-11 15:17:59 +0000
committerB. Stack <bgstack15@gmail.com>2022-10-11 15:17:59 +0000
commit38c826621a39831d1bdc78aa9e45cc592db3e77f (patch)
treea49cfd729d9793681a57fa6f7409b0f0848e9ede /zen/string_base.h
parentMerge branch 'b11.25' into 'master' (diff)
parentadd upstream 11.26 (diff)
downloadFreeFileSync-38c826621a39831d1bdc78aa9e45cc592db3e77f.tar.gz
FreeFileSync-38c826621a39831d1bdc78aa9e45cc592db3e77f.tar.bz2
FreeFileSync-38c826621a39831d1bdc78aa9e45cc592db3e77f.zip
Merge branch 'b11.26' into 'master'11.26
add upstream 11.26 See merge request opensource-tracking/FreeFileSync!49
Diffstat (limited to 'zen/string_base.h')
-rw-r--r--zen/string_base.h21
1 files changed, 11 insertions, 10 deletions
diff --git a/zen/string_base.h b/zen/string_base.h
index e18a0f16..a87827e6 100644
--- a/zen/string_base.h
+++ b/zen/string_base.h
@@ -61,11 +61,11 @@ protected:
~StorageDeepCopy() {}
Char* create(size_t size) { return create(size, size); }
- Char* create(size_t size, size_t minCapacity)
+ Char* create(size_t size, size_t capacity)
{
- assert(size <= minCapacity);
- const size_t newCapacity = AP::calcCapacity(minCapacity);
- assert(newCapacity >= minCapacity);
+ assert(size <= capacity);
+ const size_t newCapacity = AP::calcCapacity(capacity);
+ assert(newCapacity >= capacity);
Descriptor* const newDescr = static_cast<Descriptor*>(this->allocate(sizeof(Descriptor) + (newCapacity + 1) * sizeof(Char))); //throw std::bad_alloc
new (newDescr) Descriptor(size, newCapacity);
@@ -124,18 +124,18 @@ protected:
~StorageRefCountThreadSafe() {}
Char* create(size_t size) { return create(size, size); }
- Char* create(size_t size, size_t minCapacity)
+ Char* create(size_t size, size_t capacity)
{
- assert(size <= minCapacity);
+ assert(size <= capacity);
- if (minCapacity == 0) //perf: avoid memory allocation for empty string
+ if (capacity == 0) //perf: avoid memory allocation for empty string
{
++globalEmptyString.descr.refCount;
return &globalEmptyString.nullTerm;
}
- const size_t newCapacity = AP::calcCapacity(minCapacity);
- assert(newCapacity >= minCapacity);
+ const size_t newCapacity = AP::calcCapacity(capacity);
+ assert(newCapacity >= capacity);
Descriptor* const newDescr = static_cast<Descriptor*>(this->allocate(sizeof(Descriptor) + (newCapacity + 1) * sizeof(Char))); //throw std::bad_alloc
new (newDescr) Descriptor(size, newCapacity);
@@ -259,6 +259,7 @@ public:
size_t length() const;
size_t size () const { return length(); }
const Char* c_str() const { return rawStr_; } //C-string format with 0-termination
+ /**/ Char* data() { return &*begin(); }
const Char& operator[](size_t pos) const;
/**/ Char& operator[](size_t pos);
bool empty() const { return length() == 0; }
@@ -558,7 +559,7 @@ void Zbase<Char, SP>::reserve(size_t minCapacity) //make unshared and check capa
//allocate a new string
const size_t len = length();
Char* newStr = this->create(len, std::max(len, minCapacity)); //reserve() must NEVER shrink the string: logical const!
- std::copy(rawStr_, rawStr_ + len + 1, newStr); //include 0-termination
+ std::copy(rawStr_, rawStr_ + len + 1 /*0-termination*/, newStr);
this->destroy(rawStr_);
rawStr_ = newStr;
bgstack15