Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: fpdfsdk/cpdfsdk_annotiteration.cpp

Issue 2626073005: Use observed pointers in CPDFSDK_AnnotIterator. (Closed)
Patch Set: remove local Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/cpdfsdk_annotiteration.h ('k') | fpdfsdk/cpdfsdk_annotiterator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "fpdfsdk/cpdfsdk_annotiteration.h"
8
9 #include <algorithm>
10 #include <utility>
11
12 #include "fpdfsdk/cpdfsdk_annot.h"
13 #include "fpdfsdk/cpdfsdk_pageview.h"
14
15 CPDFSDK_AnnotIteration::CPDFSDK_AnnotIteration(CPDFSDK_PageView* pPageView,
16 bool bReverse) {
17 // Copying/sorting ObservedPtrs is expensive, so do it once at the end.
18 std::vector<CPDFSDK_Annot*> copiedList = pPageView->GetAnnotList();
19 std::stable_sort(copiedList.begin(), copiedList.end(),
20 [](const CPDFSDK_Annot* p1, const CPDFSDK_Annot* p2) {
21 return p1->GetLayoutOrder() < p2->GetLayoutOrder();
22 });
23
24 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
25 if (pTopMostAnnot) {
26 auto it = std::find(copiedList.begin(), copiedList.end(), pTopMostAnnot);
27 if (it != copiedList.end()) {
28 copiedList.erase(it);
29 copiedList.insert(copiedList.begin(), pTopMostAnnot);
30 }
31 }
32 if (bReverse)
33 std::reverse(copiedList.begin(), copiedList.end());
34
35 m_List.reserve(copiedList.size());
36 for (const auto& pAnnot : copiedList)
37 m_List.emplace_back(pAnnot);
38 }
39
40 CPDFSDK_AnnotIteration::~CPDFSDK_AnnotIteration() {}
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_annotiteration.h ('k') | fpdfsdk/cpdfsdk_annotiterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698