diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-02-01 13:42:30 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-02-01 13:42:30 -0800 |
commit | b9cc7a0d0ece261db2cd2a1486b05e3338bca322 (patch) | |
tree | c91de6c7848ce9cdf6eaab0a84fac27064a00c48 /fpdfsdk/include | |
parent | 58fb36a3de3174db41669c2ed0d67e4a18a4a6de (diff) | |
download | pdfium-b9cc7a0d0ece261db2cd2a1486b05e3338bca322.tar.xz |
Merge to XFA: Remove CGW_ArrayTemplate and its O(n^2 log n) sort.
Original Review URL: https://codereview.chromium.org/1652613002 .
(cherry picked from commit 0841b0f37678ba4962247f5636e9390718fc027e)
TBR=thestig@chromium.org
Review URL: https://codereview.chromium.org/1657663003 .
Diffstat (limited to 'fpdfsdk/include')
-rw-r--r-- | fpdfsdk/include/fsdk_baseform.h | 25 | ||||
-rw-r--r-- | fpdfsdk/include/fsdk_mgr.h | 74 |
2 files changed, 14 insertions, 85 deletions
diff --git a/fpdfsdk/include/fsdk_baseform.h b/fpdfsdk/include/fsdk_baseform.h index 023ea74148..0d72639b9b 100644 --- a/fpdfsdk/include/fsdk_baseform.h +++ b/fpdfsdk/include/fsdk_baseform.h @@ -14,12 +14,13 @@ #endif #include <map> +#include <vector> #include "core/include/fpdfapi/fpdf_parser.h" #include "core/include/fpdfdoc/fpdf_doc.h" #include "core/include/fxcrt/fx_basic.h" #include "core/include/fxge/fx_dib.h" -#include "fsdk_baseannot.h" +#include "fpdfsdk/include/fsdk_baseannot.h" class CFFL_FormFiller; class CPDFSDK_Annot; @@ -373,14 +374,10 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { FX_BOOL m_bNeedHightlight[kNumFieldTypes]; }; -#define BAI_STRUCTURE 0 -#define BAI_ROW 1 -#define BAI_COLUMN 2 - -#define CPDFSDK_Annots CFX_ArrayTemplate<CPDFSDK_Annot*> -#define CPDFSDK_SortAnnots CGW_ArrayTemplate<CPDFSDK_Annot*> class CBA_AnnotIterator { public: + enum TabOrder { STRUCTURE = 0, ROW, COLUMN }; + CBA_AnnotIterator(CPDFSDK_PageView* pPageView, const CFX_ByteString& sType, const CFX_ByteString& sSubType); @@ -393,15 +390,19 @@ class CBA_AnnotIterator { private: void GenerateResults(); - static int CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2); - static int CompareByTop(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2); - static CPDF_Rect GetAnnotRect(CPDFSDK_Annot* pAnnot); + static CPDF_Rect GetAnnotRect(const CPDFSDK_Annot* pAnnot); + + // Function signature compatible with std::sort(). + static bool CompareByLeftAscending(const CPDFSDK_Annot* p1, + const CPDFSDK_Annot* p2); + static bool CompareByTopDescending(const CPDFSDK_Annot* p1, + const CPDFSDK_Annot* p2); + TabOrder m_eTabOrder; CPDFSDK_PageView* m_pPageView; CFX_ByteString m_sType; CFX_ByteString m_sSubType; - int m_nTabs; - CPDFSDK_Annots m_Annots; + std::vector<CPDFSDK_Annot*> m_Annots; }; #endif // FPDFSDK_INCLUDE_FSDK_BASEFORM_H_ diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h index e53be1b1a5..042ba3811d 100644 --- a/fpdfsdk/include/fsdk_mgr.h +++ b/fpdfsdk/include/fsdk_mgr.h @@ -561,6 +561,7 @@ class CPDFSDK_Document { FX_BOOL m_bChangeMask; FX_BOOL m_bBeingDestroyed; }; + class CPDFSDK_PageView final { public: CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page); @@ -667,77 +668,4 @@ class CPDFSDK_PageView final { FX_BOOL m_bLocked; }; -template <class TYPE> -class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE> { - public: - CGW_ArrayTemplate() {} - ~CGW_ArrayTemplate() {} - - typedef int (*LP_COMPARE)(TYPE p1, TYPE p2); - - void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE) { - int nSize = this->GetSize(); - QuickSort(0, nSize - 1, bAscent, pCompare); - } - - private: - void QuickSort(FX_UINT nStartPos, - FX_UINT nStopPos, - FX_BOOL bAscend, - LP_COMPARE pCompare) { - if (nStartPos >= nStopPos) - return; - - if ((nStopPos - nStartPos) == 1) { - TYPE Value1 = this->GetAt(nStartPos); - TYPE Value2 = this->GetAt(nStopPos); - - int iGreate = (*pCompare)(Value1, Value2); - if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) { - this->SetAt(nStartPos, Value2); - this->SetAt(nStopPos, Value1); - } - return; - } - - FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2; - FX_UINT i = nStartPos; - - TYPE Value = this->GetAt(m); - - while (i < m) { - TYPE temp = this->GetAt(i); - - int iGreate = (*pCompare)(temp, Value); - if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) { - this->InsertAt(m + 1, temp); - this->RemoveAt(i); - m--; - } else { - i++; - } - } - - FX_UINT j = nStopPos; - - while (j > m) { - TYPE temp = this->GetAt(j); - - int iGreate = (*pCompare)(temp, Value); - if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0)) { - this->RemoveAt(j); - this->InsertAt(m, temp); - m++; - } else { - j--; - } - } - - if (nStartPos < m) - QuickSort(nStartPos, m, bAscend, pCompare); - if (nStopPos > m) - QuickSort(m, nStopPos, bAscend, pCompare); - } -}; - #endif // FPDFSDK_INCLUDE_FSDK_MGR_H_ |