common array: + copy constructor

introduce the copy constructor to prevent duplicated code.
This commit is contained in:
Hermet Park 2023-07-03 16:02:13 +09:00 committed by Hermet Park
parent b7dfe661b5
commit 95ebbe4339
3 changed files with 13 additions and 10 deletions

View file

@ -35,6 +35,15 @@ struct Array
uint32_t count = 0;
uint32_t reserved = 0;
Array(){}
Array(const Array& rhs)
{
reserve(rhs.reserved);
count = rhs.count;
memcpy(data, rhs.data, sizeof(T) * count);
}
void push(T element)
{
if (count + 1 > reserved) {

View file

@ -316,16 +316,10 @@ struct Shape::Impl
//Path
if (rs.path.cmds.count > 0 && rs.path.pts.count > 0) {
dup->rs.path.cmds.reserve(rs.path.cmds.reserved);
dup->rs.path.pts.reserve(rs.path.pts.reserved);
dup->rs.path.cmds.count = rs.path.cmds.count;
memcpy(dup->rs.path.cmds.data, rs.path.cmds.data, sizeof(PathCommand) * dup->rs.path.cmds.count);
dup->rs.path.pts.count = rs.path.pts.count;
memcpy(dup->rs.path.pts.data, rs.path.pts.data, sizeof(Point) * dup->rs.path.pts.count);
}
dup->rs.path.cmds = rs.path.cmds;
dup->rs.path.pts = rs.path.pts;
dup->flag |= RenderUpdateFlag::Path;
}
//Stroke
if (rs.stroke) {

View file

@ -542,7 +542,7 @@ struct SvgNodeIdPair
struct SvgLoaderData
{
Array<SvgNode*> stack = {nullptr, 0, 0};
Array<SvgNode*> stack;
SvgNode* doc = nullptr;
SvgNode* def = nullptr;
SvgNode* cssStyle = nullptr;