Make PDFiumEngine::PostPaint() more efficient
PostPaint() currently erases elements from a vector from front to back. This can potentially result in extra object moves, as every erase requires all remaining objects to be moved forward. Switch to std::erase_if(), which minimzes the number of object moves. Change-Id: Ic80e152a1892afce1104997e9f521f83cd4c4aec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5874905 Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Reviewed-by: Alan Screen <awscreen@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1357797}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
1f49958fa6
commit
7fcdfc57e1
@ -725,18 +725,15 @@ void PDFiumEngine::Paint(const gfx::Rect& rect,
|
||||
}
|
||||
|
||||
void PDFiumEngine::PostPaint() {
|
||||
for (size_t i = 0; i < progressive_paints_.size(); ++i) {
|
||||
if (progressive_paints_[i].painted())
|
||||
continue;
|
||||
|
||||
// This rectangle must have been merged with another one, that's why we
|
||||
// weren't asked to paint it. Remove it or otherwise we'll never finish
|
||||
// painting.
|
||||
FPDF_RenderPage_Close(
|
||||
pages_[progressive_paints_[i].page_index()]->GetPage());
|
||||
progressive_paints_.erase(progressive_paints_.begin() + i);
|
||||
--i;
|
||||
// Remove all entries that were never painted, as they must have been merged
|
||||
// with other entries. If they are not removed, painting will never finish.
|
||||
for (const ProgressivePaint& entry : progressive_paints_) {
|
||||
if (!entry.painted()) {
|
||||
FPDF_RenderPage_Close(pages_[entry.page_index()]->GetPage());
|
||||
}
|
||||
}
|
||||
std::erase_if(progressive_paints_,
|
||||
[](const ProgressivePaint& entry) { return !entry.painted(); });
|
||||
}
|
||||
|
||||
bool PDFiumEngine::HandleDocumentLoad(std::unique_ptr<UrlLoader> loader,
|
||||
|
Reference in New Issue
Block a user