Skip to content

Commit

Permalink
Reserve space for the line metrics styles created by ParagraphSkia::G…
Browse files Browse the repository at this point in the history
…etLineMetrics (flutter#26909)
  • Loading branch information
jason-simmons authored Jun 25, 2021
1 parent dd418a1 commit f1d78fd
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions third_party/txt/src/skia/paragraph_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "paragraph_skia.h"

#include <algorithm>
#include <numeric>

namespace txt {

Expand Down Expand Up @@ -106,6 +107,12 @@ std::vector<LineMetrics>& ParagraphSkia::GetLineMetrics() {
paragraph_->getLineMetrics(metrics);

line_metrics_.emplace();
line_metrics_styles_.reserve(
std::accumulate(metrics.begin(), metrics.end(), 0,
[](const int a, const skt::LineMetrics& b) {
return a + b.fLineMetrics.size();
}));

for (const skt::LineMetrics& skm : metrics) {
LineMetrics& txtm = line_metrics_->emplace_back(
skm.fStartIndex, skm.fEndIndex, skm.fEndExcludingWhitespaces,
Expand Down

0 comments on commit f1d78fd

Please sign in to comment.