common/array: code refactoring.

Use a default constructor with reservation.
This commit is contained in:
Hermet Park 2023-12-12 21:05:08 +09:00 committed by Hermet Park
parent 528ea0d587
commit 0aa39111ad
7 changed files with 12 additions and 16 deletions

View file

@ -38,6 +38,11 @@ struct Array
Array(){}
Array(int32_t size)
{
reserve(size);
}
Array(const Array& rhs)
{
reset();

View file

@ -329,8 +329,7 @@ static void _repeat(LottieGroup* parent, unique_ptr<Shape> path, RenderContext*
{
auto repeater = ctx->repeater;
Array<Shape*> shapes;
shapes.reserve(repeater->cnt);
Array<Shape*> shapes(repeater->cnt);
for (int i = 0; i < repeater->cnt; ++i) {
auto multiplier = repeater->offset + static_cast<float>(i);

View file

@ -85,13 +85,10 @@ struct LottieGradient
uint32_t populate(ColorStop& color)
{
uint32_t alphaCnt = (color.input->count - (colorStops.count * 4)) / 2;
Array<Fill::ColorStop> output;
output.reserve(colorStops.count + alphaCnt);
Array<Fill::ColorStop> output(colorStops.count + alphaCnt);
uint32_t cidx = 0; //color count
uint32_t clast = colorStops.count * 4;
uint32_t aidx = clast; //alpha count
Fill::ColorStop cs;
//merge color stops.

View file

@ -237,8 +237,7 @@ void LottieParser::getValue(ColorStop& color)
{
if (peekType() == kArrayType) enterArray();
color.input = new Array<float>;
color.input->reserve(context->gradient->colorStops.count);
color.input = new Array<float>(context->gradient->colorStops.count);
while (nextArrayValue()) color.input->push(getFloat());
}

View file

@ -622,8 +622,7 @@ GlRenderPass* GlRenderer::currentPass()
void GlRenderer::prepareCmpTask(GlRenderTask* task, float opacity)
{
// we use 1:1 blit mapping since compositor fbo is same size as root fbo
Array<float> vertices;
vertices.reserve(5 * 4);
Array<float> vertices(5 * 4);
float left = -1.f;
float top = 1.f;
@ -655,8 +654,7 @@ void GlRenderer::prepareCmpTask(GlRenderTask* task, float opacity)
vertices.push(1.f);
vertices.push(0.f);
Array<uint32_t> indices;
indices.reserve(6);
Array<uint32_t> indices(6);
indices.push(0);
indices.push(1);

View file

@ -123,8 +123,7 @@ struct Scene::Impl
this->renderer = &renderer;
if (clipper) {
Array<RenderData> rds;
rds.reserve(paints.size());
Array<RenderData> rds(paints.size());
for (auto paint : paints) {
rds.push(paint->pImpl->update(renderer, transform, clips, opacity, flag, true));
}

View file

@ -683,8 +683,7 @@ TvgBinCounter TvgSaver::serializeChildren(Iterator* it, const Matrix* pTransform
TvgBinCounter cnt = 0;
//Merging shapes. the result is written in the children.
Array<const Paint*> children;
children.reserve(it->count());
Array<const Paint*> children(it->count());
children.push(it->next());
while (auto child = it->next()) {