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

Unified Diff: fpdfsdk/cpdfsdk_annotiteration.cpp

Issue 2626073005: Use observed pointers in CPDFSDK_AnnotIterator. (Closed)
Patch Set: negation of condition 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 side-by-side diff with in-line comments
Download patch
Index: fpdfsdk/cpdfsdk_annotiteration.cpp
diff --git a/fpdfsdk/cpdfsdk_annotiteration.cpp b/fpdfsdk/cpdfsdk_annotiteration.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ff7a88f766111521e94d43b353eb341f295c0f57
--- /dev/null
+++ b/fpdfsdk/cpdfsdk_annotiteration.cpp
@@ -0,0 +1,38 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
dsinclair 2017/01/11 21:22:52 2017
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "fpdfsdk/cpdfsdk_annotiteration.h"
+
+#include <algorithm>
+#include <utility>
+
+#include "fpdfsdk/cpdfsdk_annot.h"
+#include "fpdfsdk/cpdfsdk_pageview.h"
+
+CPDFSDK_AnnotIteration::CPDFSDK_AnnotIteration(CPDFSDK_PageView* pPageView,
+ bool bReverse) {
+ // Copying/sorting ObservedPtrs is expensive, so do it once at the end.
+ std::vector<CPDFSDK_Annot*> copiedList = pPageView->GetAnnotList();
+ std::stable_sort(copiedList.begin(), copiedList.end(),
+ [](const CPDFSDK_Annot* p1, const CPDFSDK_Annot* p2) {
+ return p1->GetLayoutOrder() < p2->GetLayoutOrder();
+ });
+
+ CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
+ if (pTopMostAnnot) {
+ auto it = std::find(copiedList.begin(), copiedList.end(), pTopMostAnnot);
+ if (it != copiedList.end())
+ std::swap(*it, *copiedList.begin());
dsinclair 2017/01/11 21:22:52 Do we really want to swap here? Don't we just want
Tom Sepez 2017/01/11 21:34:26 Done.
+ }
+ if (bReverse)
+ std::reverse(copiedList.begin(), copiedList.end());
+
+ m_List.reserve(copiedList.size());
+ for (const auto& pAnnot : copiedList)
+ m_List.emplace_back(pAnnot);
+}
+
+CPDFSDK_AnnotIteration::~CPDFSDK_AnnotIteration() {}

Powered by Google App Engine
This is Rietveld 408576698