diff --git a/src/lib/sw_engine/tvgSwMath.cpp b/src/lib/sw_engine/tvgSwMath.cpp index bd7d0215..dbcfa754 100644 --- a/src/lib/sw_engine/tvgSwMath.cpp +++ b/src/lib/sw_engine/tvgSwMath.cpp @@ -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; } diff --git a/src/lib/sw_engine/tvgSwShape.cpp b/src/lib/sw_engine/tvgSwShape.cpp index 8568577c..14dd68b9 100644 --- a/src/lib/sw_engine/tvgSwShape.cpp +++ b/src/lib/sw_engine/tvgSwShape.cpp @@ -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); } diff --git a/src/lib/tvgArray.h b/src/lib/tvgArray.h index 0cb7b349..0e8aef30 100644 --- a/src/lib/tvgArray.h +++ b/src/lib/tvgArray.h @@ -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(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(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); diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index 631940da..246b632d 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -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); }