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

Side by Side Diff: fpdfsdk/cpdfsdk_annotiteration.cpp

Issue 2626073005: Use observed pointers in CPDFSDK_AnnotIterator. (Closed)
Patch Set: logic botch, copyright year 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 CPDFSDK_Annot* pSaved = *it;
dsinclair 2017/01/11 21:44:24 Is this needed? Won't pSaved == pTopMostAnnot?
Tom Sepez 2017/01/11 21:48:52 Done.
29 copiedList.erase(it);
30 copiedList.insert(copiedList.begin(), pSaved);
31 }
32 }
33 if (bReverse)
34 std::reverse(copiedList.begin(), copiedList.end());
35
36 m_List.reserve(copiedList.size());
37 for (const auto& pAnnot : copiedList)
38 m_List.emplace_back(pAnnot);
39 }
40
41 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