common array: revise code.

maintain code with an optimial size.
This commit is contained in:
Hermet Park 2023-07-18 21:34:49 +09:00 committed by Hermet Park
parent 055daed3f3
commit a1f0b06f41
4 changed files with 14 additions and 16 deletions

View file

@ -467,7 +467,7 @@ bool mathUpdateOutlineBBox(const SwOutline* outline, const SwBBox& clipRegion, S
auto pt = outline->pts.data;
if (outline->pts.count == 0 || outline->cntrs.count <= 0) {
if (outline->pts.empty() || outline->cntrs.empty()) {
renderRegion.reset();
return false;
}

View file

@ -63,7 +63,7 @@ static void _lineSplitAt(const Line& cur, float at, Line& left, Line& right)
static void _outlineEnd(SwOutline& outline)
{
if (outline.pts.count == 0) return;
if (outline.pts.empty()) return;
outline.cntrs.push(outline.pts.count - 1);
}

View file

@ -39,15 +39,15 @@ struct Array
Array(const Array& rhs)
{
reserve(rhs.reserved);
count = rhs.count;
memcpy(data, rhs.data, sizeof(T) * count);
reset();
*this = rhs;
}
void push(T element)
{
if (count + 1 > reserved) {
if (!reserve(count + (count >> 1) + 1)) return;
reserved = count + (count + 2) / 2;
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
}
data[count++] = element;
}
@ -63,12 +63,7 @@ struct Array
{
if (size > reserved) {
reserved = size;
auto p = data;
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
if (!data) {
data = p;
return false;
}
}
return true;
}
@ -100,10 +95,8 @@ struct Array
void reset()
{
if (data) {
free(data);
data = nullptr;
}
free(data);
data = nullptr;
count = reserved = 0;
}
@ -112,6 +105,11 @@ struct Array
count = 0;
}
bool empty() const
{
return count == 0;
}
void operator=(const Array& rhs)
{
reserve(rhs.count);

View file

@ -2671,7 +2671,7 @@ static void _inheritGradient(SvgLoaderData* loader, SvgStyleGradient* to, SvgSty
}
}
if (to->stops.count == 0) _cloneGradStops(to->stops, from->stops);
if (to->stops.empty()) _cloneGradStops(to->stops, from->stops);
}