xo-expression2: + DUniqueString, use in StringTable
This commit is contained in:
parent
d87caecce8
commit
87ddccd717
2 changed files with 48 additions and 5 deletions
|
|
@ -73,11 +73,18 @@ namespace xo {
|
|||
const char * cstr);
|
||||
|
||||
/** create string containing a copy of @p sv.
|
||||
* Use memory from allocator @p mm
|
||||
* Use memory from allocator @p mm.
|
||||
**/
|
||||
static DString * from_view(obj<AAllocator> mm,
|
||||
std::string_view sv);
|
||||
|
||||
/** create string containing a copy of @p sv.
|
||||
* Use memory from allocator @p mm via sub_alloc.
|
||||
* (load-bearing for StringTable)
|
||||
**/
|
||||
static DString * from_view_suballoc(obj<AAllocator> mm,
|
||||
std::string_view sv);
|
||||
|
||||
/** clone existing string **/
|
||||
static DString * clone(obj<AAllocator> mm,
|
||||
const DString * src);
|
||||
|
|
@ -244,6 +251,20 @@ namespace xo {
|
|||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgroup dstring-impl-methods implementation methods **/
|
||||
///@{
|
||||
|
||||
/** create instance from view @p sv, using memory from @p mm.
|
||||
* @p suballoc_flag chooses whether to use alloc() or suballoc().
|
||||
* Load-bearing for StringTable
|
||||
**/
|
||||
static DString * _from_view_aux(obj<AAllocator> mm,
|
||||
std::string_view sv,
|
||||
bool suballoc_flag);
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgroup dstring-instance-variables instance variables **/
|
||||
///@{
|
||||
|
|
|
|||
|
|
@ -58,16 +58,24 @@ namespace xo {
|
|||
}
|
||||
|
||||
DString *
|
||||
DString::from_view(obj<AAllocator> mm,
|
||||
std::string_view sv)
|
||||
DString::_from_view_aux(obj<AAllocator> mm,
|
||||
std::string_view sv,
|
||||
bool suballoc_flag)
|
||||
{
|
||||
size_type len = sv.size();
|
||||
size_type cap = len + 1;
|
||||
|
||||
void * mem = mm.alloc(typeseq::id<DString>(),
|
||||
sizeof(DString) + cap);
|
||||
auto tseq = typeseq::id<DString>();
|
||||
void * mem = nullptr;
|
||||
size_type mem_z = sizeof(DString) + cap;
|
||||
|
||||
if (suballoc_flag)
|
||||
mem = mm.sub_alloc(mem_z, false /*!complete_flag*/);
|
||||
else
|
||||
mem = mm.alloc(tseq, mem_z);
|
||||
|
||||
DString * result = new (mem) DString();
|
||||
|
||||
result->capacity_ = cap;
|
||||
result->size_ = len;
|
||||
std::memcpy(result->chars_, sv.data(), len);
|
||||
|
|
@ -76,6 +84,20 @@ namespace xo {
|
|||
return result;
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::from_view(obj<AAllocator> mm,
|
||||
std::string_view sv)
|
||||
{
|
||||
return _from_view_aux(mm, sv, false /*!suballoc_flag*/);
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::from_view_suballoc(obj<AAllocator> mm,
|
||||
std::string_view sv)
|
||||
{
|
||||
return _from_view_aux(mm, sv, true /*suballoc_flag*/);
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::clone(obj<AAllocator> mm, const DString * src)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue