mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
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:
@@ -68,6 +68,7 @@ class Flexbox : public Node {
|
||||
|
||||
void Layout(flexbox_helper::Global& global,
|
||||
bool compute_requirement = false) {
|
||||
global.blocks.reserve(children_.size());
|
||||
for (auto& child : children_) {
|
||||
flexbox_helper::Block block;
|
||||
block.min_size_x = child->requirement().min_x;
|
||||
|
@@ -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:
|
||||
|
@@ -37,6 +37,8 @@ class GridBox : public Node {
|
||||
for (const auto& line : lines_) {
|
||||
x_size = std::max(x_size, int(line.size()));
|
||||
}
|
||||
|
||||
// Fill in empty cells, in case the user did not used the API correctly:
|
||||
for (auto& line : lines_) {
|
||||
while (line.size() < size_t(x_size)) {
|
||||
line.push_back(filler());
|
||||
|
@@ -78,7 +78,7 @@ LinearGradientNormalized Normalize(LinearGradient gradient) {
|
||||
LinearGradientNormalized normalized;
|
||||
// NOLINTNEXTLINE
|
||||
normalized.angle = std::fmod(std::fmod(gradient.angle, 360.f) + 360.f, 360.f);
|
||||
for (auto& stop : gradient.stops) {
|
||||
for (const auto& stop : gradient.stops) {
|
||||
normalized.colors.push_back(stop.color);
|
||||
normalized.positions.push_back(stop.position.value()); // NOLINT
|
||||
}
|
||||
|
@@ -44,9 +44,11 @@ Table::Table() {
|
||||
|
||||
Table::Table(std::vector<std::vector<std::string>> input) {
|
||||
std::vector<std::vector<Element>> output;
|
||||
output.reserve(input.size());
|
||||
for (auto& row : input) {
|
||||
output.emplace_back();
|
||||
auto& output_row = output.back();
|
||||
output_row.reserve(row.size());
|
||||
for (auto& cell : row) {
|
||||
output_row.push_back(text(std::move(cell)));
|
||||
}
|
||||
|
@@ -46,6 +46,7 @@ Decorator operator|(Decorator a, Decorator b) {
|
||||
/// @ingroup dom
|
||||
Elements operator|(Elements elements, Decorator decorator) { // NOLINT
|
||||
Elements output;
|
||||
output.reserve(elements.size());
|
||||
for (auto& it : elements) {
|
||||
output.push_back(std::move(it) | decorator);
|
||||
}
|
||||
|
Reference in New Issue
Block a user