mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-11 08:50:24 +00:00
lottie/vector: reserve memory ahead to minimize reallocation.
Change-Id: Idb973bb7660c4ec95f36aa36d3707aa6030f5ffc
This commit is contained in:
parent
b7f8007431
commit
abb7872b79
@ -138,6 +138,7 @@ void VPath::VPathData::arcTo(const VRectF &rect, float startAngle,
|
|||||||
VPointF curve_start =
|
VPointF curve_start =
|
||||||
curvesForArc(rect, startAngle, sweepLength, pts, &point_count);
|
curvesForArc(rect, startAngle, sweepLength, pts, &point_count);
|
||||||
|
|
||||||
|
reserve(point_count + 1, point_count / 3 + 1);
|
||||||
if (isEmpty() || forceMoveTo) {
|
if (isEmpty() || forceMoveTo) {
|
||||||
moveTo(curve_start);
|
moveTo(curve_start);
|
||||||
} else {
|
} else {
|
||||||
@ -169,6 +170,7 @@ void VPath::VPathData::addOval(const VRectF &rect, VPath::Direction dir)
|
|||||||
float h2 = rect.height() / 2;
|
float h2 = rect.height() / 2;
|
||||||
float h2k = h2 * PATH_KAPPA;
|
float h2k = h2 * PATH_KAPPA;
|
||||||
|
|
||||||
|
reserve(14, 7); // 1Move + 4Cubic + 1Close
|
||||||
if (dir == VPath::Direction::CW) {
|
if (dir == VPath::Direction::CW) {
|
||||||
// moveto 12 o'clock.
|
// moveto 12 o'clock.
|
||||||
moveTo(VPointF(x + w2, y));
|
moveTo(VPointF(x + w2, y));
|
||||||
@ -200,6 +202,7 @@ void VPath::VPathData::addOval(const VRectF &rect, VPath::Direction dir)
|
|||||||
cubicTo(VPointF(x + w, y + h2 - h2k), VPointF(x + w2 + w2k, y),
|
cubicTo(VPointF(x + w, y + h2 - h2k), VPointF(x + w2 + w2k, y),
|
||||||
VPointF(x + w2, y));
|
VPointF(x + w2, y));
|
||||||
}
|
}
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VPath::VPathData::addRect(const VRectF &rect, VPath::Direction dir)
|
void VPath::VPathData::addRect(const VRectF &rect, VPath::Direction dir)
|
||||||
@ -211,6 +214,7 @@ void VPath::VPathData::addRect(const VRectF &rect, VPath::Direction dir)
|
|||||||
float w = rect.width();
|
float w = rect.width();
|
||||||
float h = rect.height();
|
float h = rect.height();
|
||||||
|
|
||||||
|
reserve(6, 6); // 1Move + 4Line + 1Close
|
||||||
if (dir == VPath::Direction::CW) {
|
if (dir == VPath::Direction::CW) {
|
||||||
moveTo(VPointF(x + w, y));
|
moveTo(VPointF(x + w, y));
|
||||||
lineTo(VPointF(x + w, y + h));
|
lineTo(VPointF(x + w, y + h));
|
||||||
@ -244,6 +248,7 @@ void VPath::VPathData::addRoundRect(const VRectF &rect, float rx, float ry,
|
|||||||
if (rx > w) rx = w;
|
if (rx > w) rx = w;
|
||||||
if (ry > h) ry = h;
|
if (ry > h) ry = h;
|
||||||
|
|
||||||
|
reserve(14, 7); // 1Move + 4Cubic + 1Close
|
||||||
if (dir == VPath::Direction::CW) {
|
if (dir == VPath::Direction::CW) {
|
||||||
moveTo(VPointF(x + w, y + ry / 2.f));
|
moveTo(VPointF(x + w, y + ry / 2.f));
|
||||||
arcTo(VRectF(x + w - rx, y + h - ry, rx, ry), 0, -90, false);
|
arcTo(VRectF(x + w - rx, y + h - ry, rx, ry), 0, -90, false);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user