From 4a21114e3a95d3798c5027de33b8e90550fc0eb7 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 1 Mar 2017 14:41:25 -0800 Subject: Use std::deque for CFX_TPOArray They both encompass the same concept: a segmented array that can grow without copying. Change-Id: Ifc02207385b1bc106df41932c7b78ec2e9cc2146 Reviewed-on: https://pdfium-review.googlesource.com/2894 Reviewed-by: dsinclair Commit-Queue: dsinclair --- xfa/fgas/layout/fgas_rtfbreak.cpp | 26 +++++++++----------- xfa/fgas/layout/fgas_rtfbreak.h | 6 ++--- xfa/fgas/layout/fgas_textbreak.cpp | 30 +++++++++++------------ xfa/fgas/layout/fgas_textbreak.h | 14 +++++++---- xfa/fgas/layout/fgas_unicode.cpp | 49 -------------------------------------- xfa/fgas/layout/fgas_unicode.h | 21 ---------------- 6 files changed, 38 insertions(+), 108 deletions(-) delete mode 100644 xfa/fgas/layout/fgas_unicode.cpp delete mode 100644 xfa/fgas/layout/fgas_unicode.h (limited to 'xfa/fgas/layout') diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp index 648897818f..9a83be65ac 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.cpp +++ b/xfa/fgas/layout/fgas_rtfbreak.cpp @@ -13,7 +13,6 @@ #include "third_party/base/stl_util.h" #include "xfa/fgas/font/cfgas_gefont.h" #include "xfa/fgas/layout/fgas_linebreak.h" -#include "xfa/fgas/layout/fgas_unicode.h" namespace { @@ -433,14 +432,13 @@ CFX_RTFBreakType CFX_RTFBreak::EndBreak(CFX_RTFBreakType dwStatus) { m_pCurLine == &m_RTFLine1 ? &m_RTFLine2 : &m_RTFLine1; bool bAllChars = m_iAlignment == CFX_RTFLineAlignment::Justified || m_iAlignment == CFX_RTFLineAlignment::Distributed; - CFX_TPOArray tpos(100); + if (!EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) { + std::deque tpos; EndBreak_BidiLine(&tpos, dwStatus); - if (!m_bPagination && m_iAlignment != CFX_RTFLineAlignment::Left) EndBreak_Alignment(tpos, bAllChars, dwStatus); } - m_pCurLine = pNextLine; m_pCurLine->m_iStart = m_iBoundaryStart; @@ -521,7 +519,7 @@ bool CFX_RTFBreak::EndBreak_SplitLine(CFX_RTFLine* pNextLine, return true; } -void CFX_RTFBreak::EndBreak_BidiLine(CFX_TPOArray* tpos, +void CFX_RTFBreak::EndBreak_BidiLine(std::deque* tpos, CFX_RTFBreakType dwStatus) { FX_TPO tpo; CFX_RTFPiece tp; @@ -584,7 +582,7 @@ void CFX_RTFBreak::EndBreak_BidiLine(CFX_TPOArray* tpos, tp.m_iStartChar = i; tpo.index = j++; tpo.pos = tp.m_iBidiPos; - tpos->Add(tpo); + tpos->push_back(tpo); iBidiLevel = -1; } else { iCharWidth = pTC->m_iCharWidth; @@ -600,21 +598,19 @@ void CFX_RTFBreak::EndBreak_BidiLine(CFX_TPOArray* tpos, pCurPieces->Add(tp); tpo.index = j; tpo.pos = tp.m_iBidiPos; - tpos->Add(tpo); + tpos->push_back(tpo); } - j = tpos->GetSize() - 1; - FX_TEXTLAYOUT_PieceSort(*tpos, 0, j); + std::sort(tpos->begin(), tpos->end()); int32_t iStartPos = m_pCurLine->m_iStart; - for (i = 0; i <= j; i++) { - tpo = tpos->GetAt(i); - CFX_RTFPiece& ttp = pCurPieces->GetAt(tpo.index); + for (const auto& it : *tpos) { + CFX_RTFPiece& ttp = pCurPieces->GetAt(it.index); ttp.m_iStartPos = iStartPos; iStartPos += ttp.m_iWidth; } } -void CFX_RTFBreak::EndBreak_Alignment(const CFX_TPOArray& tpos, +void CFX_RTFBreak::EndBreak_Alignment(const std::deque& tpos, bool bAllChars, CFX_RTFBreakType dwStatus) { CFX_RTFPieceArray* pCurPieces = &m_pCurLine->m_LinePieces; @@ -628,7 +624,7 @@ void CFX_RTFBreak::EndBreak_Alignment(const CFX_TPOArray& tpos, int32_t j; FX_TPO tpo; for (i = iCount - 1; i > -1; i--) { - tpo = tpos.GetAt(i); + tpo = tpos[i]; CFX_RTFPiece& ttp = pCurPieces->GetAt(tpo.index); if (!bFind) iNetWidth = ttp.GetEndPos(); @@ -667,7 +663,7 @@ void CFX_RTFBreak::EndBreak_Alignment(const CFX_TPOArray& tpos, dwStatus != CFX_RTFBreakType::Paragraph))) { int32_t iStart = -1; for (i = 0; i < iCount; i++) { - tpo = tpos.GetAt(i); + tpo = tpos[i]; CFX_RTFPiece& ttp = pCurPieces->GetAt(tpo.index); if (iStart < 0) iStart = ttp.m_iStartPos; diff --git a/xfa/fgas/layout/fgas_rtfbreak.h b/xfa/fgas/layout/fgas_rtfbreak.h index 2b6c2cf19f..4d999ec682 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.h +++ b/xfa/fgas/layout/fgas_rtfbreak.h @@ -7,6 +7,7 @@ #ifndef XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ #define XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ +#include #include #include "core/fxcrt/cfx_retain_ptr.h" @@ -14,7 +15,6 @@ #include "core/fxcrt/fx_ucd.h" #include "xfa/fgas/crt/fgas_utils.h" #include "xfa/fgas/layout/fgas_textbreak.h" -#include "xfa/fgas/layout/fgas_unicode.h" class CFGAS_GEFont; @@ -195,8 +195,8 @@ class CFX_RTFBreak { bool EndBreak_SplitLine(CFX_RTFLine* pNextLine, bool bAllChars, CFX_RTFBreakType dwStatus); - void EndBreak_BidiLine(CFX_TPOArray* tpos, CFX_RTFBreakType dwStatus); - void EndBreak_Alignment(const CFX_TPOArray& tpos, + void EndBreak_BidiLine(std::deque* tpos, CFX_RTFBreakType dwStatus); + void EndBreak_Alignment(const std::deque& tpos, bool bAllChars, CFX_RTFBreakType dwStatus); diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp index ad7ab91598..fd1646503e 100644 --- a/xfa/fgas/layout/fgas_textbreak.cpp +++ b/xfa/fgas/layout/fgas_textbreak.cpp @@ -14,7 +14,6 @@ #include "third_party/base/ptr_util.h" #include "xfa/fgas/font/cfgas_gefont.h" #include "xfa/fgas/layout/fgas_linebreak.h" -#include "xfa/fgas/layout/fgas_unicode.h" namespace { @@ -695,7 +694,8 @@ bool CFX_TxtBreak::EndBreak_SplitLine(CFX_TxtLine* pNextLine, return false; } -void CFX_TxtBreak::EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus) { +void CFX_TxtBreak::EndBreak_BidiLine(std::deque* tpos, + uint32_t dwStatus) { CFX_TxtPiece tp; FX_TPO tpo; CFX_TxtChar* pTC; @@ -755,7 +755,7 @@ void CFX_TxtBreak::EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus) { tp.m_iStartChar = i; tpo.index = ++j; tpo.pos = tp.m_iBidiPos; - tpos.Add(tpo); + tpos->push_back(tpo); iBidiLevel = -1; } else { iCharWidth = pTC->m_iCharWidth; @@ -771,14 +771,14 @@ void CFX_TxtBreak::EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus) { pCurPieces->Add(tp); tpo.index = ++j; tpo.pos = tp.m_iBidiPos; - tpos.Add(tpo); + tpos->push_back(tpo); } if (j > -1) { if (j > 0) { - FX_TEXTLAYOUT_PieceSort(tpos, 0, j); + std::sort(tpos->begin(), tpos->end()); int32_t iStartPos = 0; for (i = 0; i <= j; i++) { - tpo = tpos.GetAt(i); + tpo = (*tpos)[i]; CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index); ttp.m_iStartPos = iStartPos; iStartPos += ttp.m_iWidth; @@ -800,13 +800,11 @@ void CFX_TxtBreak::EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus) { tp.m_iHorizontalScale = pTC->m_iHorizontalScale; tp.m_iVerticalScale = pTC->m_iVerticalScale; pCurPieces->Add(tp); - tpo.index = 0; - tpo.pos = 0; - tpos.Add(tpo); + tpos->push_back({0, 0}); } } -void CFX_TxtBreak::EndBreak_Alignment(CFX_TPOArray& tpos, +void CFX_TxtBreak::EndBreak_Alignment(const std::deque& tpos, bool bAllChars, uint32_t dwStatus) { int32_t iNetWidth = m_pCurLine->m_iWidth; @@ -821,7 +819,7 @@ void CFX_TxtBreak::EndBreak_Alignment(CFX_TPOArray& tpos, CFX_TxtChar* pTC; FX_CHARTYPE chartype; for (i = iCount - 1; i > -1; i--) { - tpo = tpos.GetAt(i); + tpo = tpos[i]; CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index); if (!bFind) iNetWidth = ttp.GetEndPos(); @@ -860,7 +858,7 @@ void CFX_TxtBreak::EndBreak_Alignment(CFX_TPOArray& tpos, dwStatus != FX_TXTBREAK_ParagraphBreak))) { int32_t iStart = -1; for (i = 0; i < iCount; i++) { - tpo = tpos.GetAt(i); + tpo = tpos[i]; CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index); if (iStart < -1) iStart = ttp.m_iStartPos; @@ -937,18 +935,18 @@ uint32_t CFX_TxtBreak::EndBreak(uint32_t dwStatus) { CFX_TxtLine* pNextLine = (m_pCurLine == m_pTxtLine1.get()) ? m_pTxtLine2.get() : m_pTxtLine1.get(); bool bAllChars = (m_iCurAlignment > FX_TXTLINEALIGNMENT_Right); - CFX_TPOArray tpos(100); - CFX_Char* pTC; if (m_bArabicShapes) EndBreak_UpdateArabicShapes(); + if (!EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) { - EndBreak_BidiLine(tpos, dwStatus); + std::deque tpos; + EndBreak_BidiLine(&tpos, dwStatus); if (!m_bPagination && m_iCurAlignment > FX_TXTLINEALIGNMENT_Left) EndBreak_Alignment(tpos, bAllChars, dwStatus); } m_pCurLine = pNextLine; - pTC = GetLastChar(0, false); + CFX_Char* pTC = GetLastChar(0, false); m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown; if (dwStatus == FX_TXTBREAK_ParagraphBreak) { m_iArabicContext = m_iCurArabicContext = 1; diff --git a/xfa/fgas/layout/fgas_textbreak.h b/xfa/fgas/layout/fgas_textbreak.h index cadfcf12bc..b64a2422eb 100644 --- a/xfa/fgas/layout/fgas_textbreak.h +++ b/xfa/fgas/layout/fgas_textbreak.h @@ -7,6 +7,7 @@ #ifndef XFA_FGAS_LAYOUT_FGAS_TEXTBREAK_H_ #define XFA_FGAS_LAYOUT_FGAS_TEXTBREAK_H_ +#include #include #include @@ -14,13 +15,13 @@ #include "core/fxge/cfx_renderdevice.h" #include "third_party/base/stl_util.h" #include "xfa/fgas/crt/fgas_utils.h" -#include "xfa/fgas/layout/fgas_unicode.h" class CFX_Char; class CFGAS_GEFont; class CFX_TxtChar; class CFX_TxtPiece; class IFX_TxtAccess; +struct FDE_TEXTEDITPIECE; #define FX_TXTBREAKPOLICY_None 0x00 #define FX_TXTBREAKPOLICY_Pagination 0x01 @@ -74,7 +75,12 @@ class IFX_TxtAccess; #define FX_TXTLINEALIGNMENT_HigherMask 0x0C #define FX_TXTBREAK_MinimumTabWidth 160000 -struct FDE_TEXTEDITPIECE; +struct FX_TPO { + int32_t index; + int32_t pos; + + bool operator<(const FX_TPO& that) const { return pos < that.pos; } +}; class IFX_TxtAccess { public: @@ -252,8 +258,8 @@ class CFX_TxtBreak { bool EndBreak_SplitLine(CFX_TxtLine* pNextLine, bool bAllChars, uint32_t dwStatus); - void EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus); - void EndBreak_Alignment(CFX_TPOArray& tpos, + void EndBreak_BidiLine(std::deque* tpos, uint32_t dwStatus); + void EndBreak_Alignment(const std::deque& tpos, bool bAllChars, uint32_t dwStatus); int32_t GetBreakPos(std::vector& ca, diff --git a/xfa/fgas/layout/fgas_unicode.cpp b/xfa/fgas/layout/fgas_unicode.cpp deleted file mode 100644 index 10fdbf0810..0000000000 --- a/xfa/fgas/layout/fgas_unicode.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// 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 "xfa/fgas/layout/fgas_unicode.h" - -void FX_TEXTLAYOUT_PieceSort(CFX_TPOArray& tpos, int32_t iStart, int32_t iEnd) { - ASSERT(iStart > -1 && iStart < tpos.GetSize()); - ASSERT(iEnd > -1 && iEnd < tpos.GetSize()); - if (iStart >= iEnd) { - return; - } - int32_t i = iStart, j = iEnd; - FX_TPO *pCur = tpos.GetPtrAt(iStart), *pSort; - int32_t v = pCur->pos; - while (i < j) { - while (j > i) { - pSort = tpos.GetPtrAt(j); - if (pSort->pos < v) { - FX_TPO t = *pSort; - *pSort = *pCur; - *pCur = t; - pCur = pSort; - break; - } - j--; - } - while (i < j) { - pSort = tpos.GetPtrAt(i); - if (pSort->pos > v) { - FX_TPO t = *pSort; - *pSort = *pCur; - *pCur = t; - pCur = pSort; - break; - } - i++; - } - } - i--, j++; - if (iStart < i) { - FX_TEXTLAYOUT_PieceSort(tpos, iStart, i); - } - if (j < iEnd) { - FX_TEXTLAYOUT_PieceSort(tpos, j, iEnd); - } -} diff --git a/xfa/fgas/layout/fgas_unicode.h b/xfa/fgas/layout/fgas_unicode.h deleted file mode 100644 index 0a1fbfe440..0000000000 --- a/xfa/fgas/layout/fgas_unicode.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// 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 - -#ifndef XFA_FGAS_LAYOUT_FGAS_UNICODE_H_ -#define XFA_FGAS_LAYOUT_FGAS_UNICODE_H_ - -#include "xfa/fgas/crt/fgas_utils.h" -#include "xfa/fgas/font/cfgas_fontmgr.h" - -struct FX_TPO { - int32_t index; - int32_t pos; -}; -typedef CFX_MassArrayTemplate CFX_TPOArray; - -void FX_TEXTLAYOUT_PieceSort(CFX_TPOArray& tpos, int32_t iStart, int32_t iEnd); - -#endif // XFA_FGAS_LAYOUT_FGAS_UNICODE_H_ -- cgit v1.2.3