Optimize inserts in vector and refactor const reference objects (#659)

Signed-off-by: German Semenov <GermanAizek@yandex.ru>
Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Herman Semenov
2023-05-31 20:24:08 +03:00
committed by GitHub
parent 8bea9261bc
commit d464a071da
10 changed files with 21 additions and 4 deletions

View File

@@ -88,6 +88,7 @@ struct Line {
void SetX(Global& global, std::vector<Line> lines) {
for (auto& line : lines) {
std::vector<box_helper::Element> elements;
elements.reserve(line.blocks.size());
for (auto* block : line.blocks) {
box_helper::Element element;
element.min_size = block->min_size_x;
@@ -117,6 +118,7 @@ void SetX(Global& global, std::vector<Line> lines) {
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
void SetY(Global& g, std::vector<Line> lines) {
std::vector<box_helper::Element> elements;
elements.reserve(lines.size());
for (auto& line : lines) {
box_helper::Element element;
element.flex_shrink = line.blocks.front()->flex_shrink_y;
@@ -317,6 +319,7 @@ void Compute3(Global& global) {
{
Line line;
int x = 0;
line.blocks.reserve(global.blocks.size());
for (auto& block : global.blocks) {
// Does it fit the end of the row?
// No? Then we need to start a new one: