mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 04:24:28 +00:00
common array: revise code.
maintain code with an optimial size.
This commit is contained in:
parent
055daed3f3
commit
a1f0b06f41
4 changed files with 14 additions and 16 deletions
|
@ -467,7 +467,7 @@ bool mathUpdateOutlineBBox(const SwOutline* outline, const SwBBox& clipRegion, S
|
||||||
|
|
||||||
auto pt = outline->pts.data;
|
auto pt = outline->pts.data;
|
||||||
|
|
||||||
if (outline->pts.count == 0 || outline->cntrs.count <= 0) {
|
if (outline->pts.empty() || outline->cntrs.empty()) {
|
||||||
renderRegion.reset();
|
renderRegion.reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ static void _lineSplitAt(const Line& cur, float at, Line& left, Line& right)
|
||||||
|
|
||||||
static void _outlineEnd(SwOutline& outline)
|
static void _outlineEnd(SwOutline& outline)
|
||||||
{
|
{
|
||||||
if (outline.pts.count == 0) return;
|
if (outline.pts.empty()) return;
|
||||||
outline.cntrs.push(outline.pts.count - 1);
|
outline.cntrs.push(outline.pts.count - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,15 +39,15 @@ struct Array
|
||||||
|
|
||||||
Array(const Array& rhs)
|
Array(const Array& rhs)
|
||||||
{
|
{
|
||||||
reserve(rhs.reserved);
|
reset();
|
||||||
count = rhs.count;
|
*this = rhs;
|
||||||
memcpy(data, rhs.data, sizeof(T) * count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void push(T element)
|
void push(T element)
|
||||||
{
|
{
|
||||||
if (count + 1 > reserved) {
|
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;
|
data[count++] = element;
|
||||||
}
|
}
|
||||||
|
@ -63,12 +63,7 @@ struct Array
|
||||||
{
|
{
|
||||||
if (size > reserved) {
|
if (size > reserved) {
|
||||||
reserved = size;
|
reserved = size;
|
||||||
auto p = data;
|
|
||||||
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
||||||
if (!data) {
|
|
||||||
data = p;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -100,10 +95,8 @@ struct Array
|
||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
if (data) {
|
free(data);
|
||||||
free(data);
|
data = nullptr;
|
||||||
data = nullptr;
|
|
||||||
}
|
|
||||||
count = reserved = 0;
|
count = reserved = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +105,11 @@ struct Array
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool empty() const
|
||||||
|
{
|
||||||
|
return count == 0;
|
||||||
|
}
|
||||||
|
|
||||||
void operator=(const Array& rhs)
|
void operator=(const Array& rhs)
|
||||||
{
|
{
|
||||||
reserve(rhs.count);
|
reserve(rhs.count);
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue