summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-05-17 13:42:51 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-17 13:42:51 -0700
commit8bdb290b9301200aeafa8b89678e690166ba1ce6 (patch)
treed4f6e474169f0a3ce1e435ac5571883bacb10f57
parent992def065be348d6f8157fab75aee312f5f45558 (diff)
downloadpdfium-8bdb290b9301200aeafa8b89678e690166ba1ce6.tar.xz
Remove Release() from IFX_CharIter, use unique_ptrs.chromium/2742chromium/2741
Review-Url: https://codereview.chromium.org/1986373002
-rw-r--r--xfa/fee/fde_txtedtbuf.cpp5
-rw-r--r--xfa/fee/fde_txtedtbuf.h19
-rw-r--r--xfa/fee/fde_txtedtengine.cpp4
-rw-r--r--xfa/fee/fde_txtedtpage.cpp30
-rw-r--r--xfa/fee/fde_txtedtpage.h4
-rw-r--r--xfa/fee/fde_txtedtparag.cpp9
-rw-r--r--xfa/fee/fx_wordbreak/fx_wordbreak.h28
-rw-r--r--xfa/fee/fx_wordbreak/fx_wordbreak_impl.cpp71
-rw-r--r--xfa/fee/ifde_txtedtengine.h2
9 files changed, 72 insertions, 100 deletions
diff --git a/xfa/fee/fde_txtedtbuf.cpp b/xfa/fee/fde_txtedtbuf.cpp
index c9ad39252b..def92012e0 100644
--- a/xfa/fee/fde_txtedtbuf.cpp
+++ b/xfa/fee/fde_txtedtbuf.cpp
@@ -29,10 +29,9 @@ CFDE_TxtEdtBufIter::CFDE_TxtEdtBufIter(CFDE_TxtEdtBuf* pBuf, FX_WCHAR wcAlias)
m_Alias(wcAlias) {
ASSERT(m_pBuf);
}
+
CFDE_TxtEdtBufIter::~CFDE_TxtEdtBufIter() {}
-void CFDE_TxtEdtBufIter::Release() {
- delete this;
-}
+
FX_BOOL CFDE_TxtEdtBufIter::Next(FX_BOOL bPrev) {
if (bPrev) {
if (m_nIndex == 0) {
diff --git a/xfa/fee/fde_txtedtbuf.h b/xfa/fee/fde_txtedtbuf.h
index 673d2b98ca..bcfb66a0a1 100644
--- a/xfa/fee/fde_txtedtbuf.h
+++ b/xfa/fee/fde_txtedtbuf.h
@@ -10,23 +10,19 @@
#include "xfa/fee/ifde_txtedtengine.h"
#include "xfa/fgas/crt/fgas_memory.h"
-class IFX_CharIter;
class CFDE_TxtEdtBuf;
class CFDE_TxtEdtBufIter : public IFX_CharIter {
public:
CFDE_TxtEdtBufIter(CFDE_TxtEdtBuf* pBuf, FX_WCHAR wcAlias = 0);
+ ~CFDE_TxtEdtBufIter() override;
- virtual void Release();
- virtual FX_BOOL Next(FX_BOOL bPrev = FALSE);
- virtual FX_WCHAR GetChar();
- virtual void SetAt(int32_t nIndex);
- virtual int32_t GetAt() const;
- virtual FX_BOOL IsEOF(FX_BOOL bTail = TRUE) const;
- virtual IFX_CharIter* Clone();
-
- protected:
- ~CFDE_TxtEdtBufIter();
+ FX_BOOL Next(FX_BOOL bPrev = FALSE) override;
+ FX_WCHAR GetChar() override;
+ void SetAt(int32_t nIndex) override;
+ int32_t GetAt() const override;
+ FX_BOOL IsEOF(FX_BOOL bTail = TRUE) const override;
+ IFX_CharIter* Clone() override;
private:
CFDE_TxtEdtBuf* m_pBuf;
@@ -35,6 +31,7 @@ class CFDE_TxtEdtBufIter : public IFX_CharIter {
int32_t m_nIndex;
FX_WCHAR m_Alias;
};
+
class CFDE_TxtEdtBuf {
public:
CFDE_TxtEdtBuf();
diff --git a/xfa/fee/fde_txtedtengine.cpp b/xfa/fee/fde_txtedtengine.cpp
index 71f510205b..826f0ce62c 100644
--- a/xfa/fee/fde_txtedtengine.cpp
+++ b/xfa/fee/fde_txtedtengine.cpp
@@ -954,7 +954,8 @@ void CFDE_TxtEdtEngine::RebuildParagraphs() {
FX_WCHAR wChar = L' ';
int32_t nParagStart = 0;
int32_t nIndex = 0;
- IFX_CharIter* pIter = new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)m_pTxtBuf);
+ std::unique_ptr<IFX_CharIter> pIter(
+ new CFDE_TxtEdtBufIter(static_cast<CFDE_TxtEdtBuf*>(m_pTxtBuf)));
pIter->SetAt(0);
do {
wChar = pIter->GetChar();
@@ -968,7 +969,6 @@ void CFDE_TxtEdtEngine::RebuildParagraphs() {
nParagStart = nIndex + 1;
}
} while (pIter->Next());
- pIter->Release();
}
void CFDE_TxtEdtEngine::RemoveAllParags() {
diff --git a/xfa/fee/fde_txtedtpage.cpp b/xfa/fee/fde_txtedtpage.cpp
index d46e1a11b0..87d128ad56 100644
--- a/xfa/fee/fde_txtedtpage.cpp
+++ b/xfa/fee/fde_txtedtpage.cpp
@@ -143,8 +143,6 @@ CFDE_TxtEdtPage::~CFDE_TxtEdtPage() {
m_PieceMassArr.RemoveAll(TRUE);
delete m_pTextSet;
delete[] m_pCharWidth;
- if (m_pIter)
- m_pIter->Release();
}
void CFDE_TxtEdtPage::Release() {
@@ -357,13 +355,11 @@ int32_t CFDE_TxtEdtPage::SelectWord(const CFX_PointF& fPoint, int32_t& nCount) {
if (nIndex < 0) {
return -1;
}
- CFX_WordBreak* pIter = new CFX_WordBreak;
+ std::unique_ptr<CFX_WordBreak> pIter(new CFX_WordBreak);
pIter->Attach(new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)pBuf));
pIter->SetAt(nIndex);
nCount = pIter->GetWordLength();
- int32_t nRet = pIter->GetWordPos();
- pIter->Release();
- return nRet;
+ return pIter->GetWordPos();
}
FX_BOOL CFDE_TxtEdtPage::IsLoaded(const CFX_RectF* pClipBox) {
return m_bLoaded;
@@ -376,14 +372,12 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox,
}
CFDE_TxtEdtBuf* pBuf = m_pEditEngine->GetTextBuf();
const FDE_TXTEDTPARAMS* pParams = m_pEditEngine->GetEditParams();
- if (m_pIter != NULL) {
- m_pIter->Release();
- }
FX_WCHAR wcAlias = 0;
if (pParams->dwMode & FDE_TEXTEDITMODE_Password) {
wcAlias = m_pEditEngine->GetAliasChar();
}
- m_pIter = new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)pBuf, wcAlias);
+ m_pIter.reset(
+ new CFDE_TxtEdtBufIter(static_cast<CFDE_TxtEdtBuf*>(pBuf), wcAlias));
CFX_TxtBreak* pBreak = m_pEditEngine->GetTextBreak();
pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak);
pBreak->ClearBreakPieces();
@@ -429,7 +423,7 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox,
m_nCharCount = nPageEnd - nPageStart + 1;
FX_BOOL bReload = FALSE;
FX_FLOAT fDefCharWidth = 0;
- IFX_CharIter* pIter = m_pIter->Clone();
+ std::unique_ptr<IFX_CharIter> pIter(m_pIter->Clone());
pIter->SetAt(nPageStart);
m_pIter->SetAt(nPageStart);
FX_BOOL bFirstPiece = TRUE;
@@ -543,7 +537,6 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox,
FDE_TEXTEDITPIECE* pPiece = m_PieceMassArr.GetPtrAt(nCount - 1);
pPiece->rtPiece.height = pParams->fFontSize;
}
- pIter->Release();
m_nRefCount = 1;
m_bLoaded = TRUE;
return 0;
@@ -560,16 +553,15 @@ void CFDE_TxtEdtPage::UnloadPage(const CFX_RectF* pClipBox) {
m_pTextSet = nullptr;
delete[] m_pCharWidth;
m_pCharWidth = nullptr;
- if (m_pBgnParag)
+ if (m_pBgnParag) {
m_pBgnParag->UnloadParag();
- if (m_pEndParag)
+ m_pBgnParag = nullptr;
+ }
+ if (m_pEndParag) {
m_pEndParag->UnloadParag();
- if (m_pIter) {
- m_pIter->Release();
- m_pIter = nullptr;
+ m_pEndParag = nullptr;
}
- m_pBgnParag = nullptr;
- m_pEndParag = nullptr;
+ m_pIter.reset();
}
const CFX_RectF& CFDE_TxtEdtPage::GetContentsBox() {
diff --git a/xfa/fee/fde_txtedtpage.h b/xfa/fee/fde_txtedtpage.h
index 8ac104c2a7..81f29fed49 100644
--- a/xfa/fee/fde_txtedtpage.h
+++ b/xfa/fee/fde_txtedtpage.h
@@ -7,6 +7,8 @@
#ifndef XFA_FEE_FDE_TXTEDTPAGE_H_
#define XFA_FEE_FDE_TXTEDTPAGE_H_
+#include <memory>
+
#include "core/fxcrt/include/fx_coordinates.h"
#include "core/fxcrt/include/fx_string.h"
#include "xfa/fde/fde_visualset.h"
@@ -147,7 +149,7 @@ class CFDE_TxtEdtPage : public IFDE_TxtEdtPage {
const CFX_RectF& rtF,
FX_FLOAT fTolerance) const;
- IFX_CharIter* m_pIter;
+ std::unique_ptr<IFX_CharIter> m_pIter;
CFDE_TxtEdtTextSet* m_pTextSet;
CFDE_TxtEdtEngine* m_pEditEngine;
CFDE_TXTEDTPieceMassArray m_PieceMassArr;
diff --git a/xfa/fee/fde_txtedtparag.cpp b/xfa/fee/fde_txtedtparag.cpp
index f49f43147d..4f5b5a15df 100644
--- a/xfa/fee/fde_txtedtparag.cpp
+++ b/xfa/fee/fde_txtedtparag.cpp
@@ -37,8 +37,8 @@ void CFDE_TxtEdtParag::LoadParag() {
if (pParam->dwMode & FDE_TEXTEDITMODE_Password) {
wcAlias = m_pEngine->GetAliasChar();
}
- IFX_CharIter* pIter =
- new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)pTxtBuf, wcAlias);
+ std::unique_ptr<IFX_CharIter> pIter(
+ new CFDE_TxtEdtBufIter(static_cast<CFDE_TxtEdtBuf*>(pTxtBuf), wcAlias));
pIter->SetAt(m_nCharStart);
int32_t nEndIndex = m_nCharStart + m_nCharCount;
CFX_ArrayTemplate<int32_t> LineBaseArr;
@@ -71,7 +71,6 @@ void CFDE_TxtEdtParag::LoadParag() {
pIter->Next(TRUE);
}
} while (pIter->Next(FALSE) && (pIter->GetAt() < nEndIndex));
- pIter->Release();
pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak);
pTxtBreak->ClearBreakPieces();
int32_t nLineCount = LineBaseArr.GetSize();
@@ -102,10 +101,11 @@ void CFDE_TxtEdtParag::UnloadParag() {
void CFDE_TxtEdtParag::CalcLines() {
CFX_TxtBreak* pTxtBreak = m_pEngine->GetTextBreak();
CFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf();
- IFX_CharIter* pIter = new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)pTxtBuf);
int32_t nCount = 0;
uint32_t dwBreakStatus = FX_TXTBREAK_None;
int32_t nEndIndex = m_nCharStart + m_nCharCount;
+ std::unique_ptr<IFX_CharIter> pIter(
+ new CFDE_TxtEdtBufIter(static_cast<CFDE_TxtEdtBuf*>(pTxtBuf)));
pIter->SetAt(m_nCharStart);
FX_BOOL bReload = FALSE;
do {
@@ -129,7 +129,6 @@ void CFDE_TxtEdtParag::CalcLines() {
pIter->Next(TRUE);
}
} while (pIter->Next(FALSE) && (pIter->GetAt() < nEndIndex));
- pIter->Release();
pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak);
pTxtBreak->ClearBreakPieces();
m_nLineCount = nCount;
diff --git a/xfa/fee/fx_wordbreak/fx_wordbreak.h b/xfa/fee/fx_wordbreak/fx_wordbreak.h
index 7192700b9a..e1b1787579 100644
--- a/xfa/fee/fx_wordbreak/fx_wordbreak.h
+++ b/xfa/fee/fx_wordbreak/fx_wordbreak.h
@@ -7,33 +7,34 @@
#ifndef XFA_FEE_FX_WORDBREAK_FX_WORDBREAK_H_
#define XFA_FEE_FX_WORDBREAK_FX_WORDBREAK_H_
+#include <memory>
+
#include "core/fxcrt/include/fx_string.h"
#include "core/fxcrt/include/fx_system.h"
#include "xfa/fee/ifde_txtedtengine.h"
class CFX_CharIter : public IFX_CharIter {
public:
- CFX_CharIter(const CFX_WideString& wsText);
- virtual void Release();
- virtual FX_BOOL Next(FX_BOOL bPrev = FALSE);
- virtual FX_WCHAR GetChar();
- virtual void SetAt(int32_t nIndex);
- virtual int32_t GetAt() const;
- virtual FX_BOOL IsEOF(FX_BOOL bTail = TRUE) const;
- virtual IFX_CharIter* Clone();
+ explicit CFX_CharIter(const CFX_WideString& wsText);
+ ~CFX_CharIter() override;
- protected:
- ~CFX_CharIter();
+ FX_BOOL Next(FX_BOOL bPrev = FALSE) override;
+ FX_WCHAR GetChar() override;
+ void SetAt(int32_t nIndex) override;
+ int32_t GetAt() const override;
+ FX_BOOL IsEOF(FX_BOOL bTail = TRUE) const override;
+ IFX_CharIter* Clone() override;
private:
const CFX_WideString& m_wsText;
int32_t m_nIndex;
};
+
class CFX_WordBreak {
public:
CFX_WordBreak();
+ ~CFX_WordBreak();
- void Release();
void Attach(IFX_CharIter* pIter);
void Attach(const CFX_WideString& wsText);
FX_BOOL Next(FX_BOOL bPrev);
@@ -44,14 +45,13 @@ class CFX_WordBreak {
FX_BOOL IsEOF(FX_BOOL bTail) const;
protected:
- ~CFX_WordBreak();
FX_BOOL FindNextBreakPos(IFX_CharIter* pIter,
FX_BOOL bPrev,
FX_BOOL bFromNext = TRUE);
private:
- IFX_CharIter* m_pPreIter;
- IFX_CharIter* m_pCurIter;
+ std::unique_ptr<IFX_CharIter> m_pPreIter;
+ std::unique_ptr<IFX_CharIter> m_pCurIter;
};
#endif // XFA_FEE_FX_WORDBREAK_FX_WORDBREAK_H_
diff --git a/xfa/fee/fx_wordbreak/fx_wordbreak_impl.cpp b/xfa/fee/fx_wordbreak/fx_wordbreak_impl.cpp
index 408558a9ca..eda5368afb 100644
--- a/xfa/fee/fx_wordbreak/fx_wordbreak_impl.cpp
+++ b/xfa/fee/fx_wordbreak/fx_wordbreak_impl.cpp
@@ -12,14 +12,14 @@ FX_WordBreakProp FX_GetWordBreakProperty(FX_WCHAR wcCodePoint) {
return (FX_WordBreakProp)(((wcCodePoint)&1) ? (dwProperty & 0x0F)
: (dwProperty >> 4));
}
+
CFX_CharIter::CFX_CharIter(const CFX_WideString& wsText)
: m_wsText(wsText), m_nIndex(0) {
ASSERT(!wsText.IsEmpty());
}
+
CFX_CharIter::~CFX_CharIter() {}
-void CFX_CharIter::Release() {
- delete this;
-}
+
FX_BOOL CFX_CharIter::Next(FX_BOOL bPrev) {
if (bPrev) {
if (m_nIndex <= 0) {
@@ -54,60 +54,46 @@ IFX_CharIter* CFX_CharIter::Clone() {
pIter->m_nIndex = m_nIndex;
return pIter;
}
-CFX_WordBreak::CFX_WordBreak() : m_pPreIter(NULL), m_pCurIter(NULL) {}
-CFX_WordBreak::~CFX_WordBreak() {
- if (m_pPreIter) {
- m_pPreIter->Release();
- m_pPreIter = NULL;
- }
- if (m_pCurIter) {
- m_pCurIter->Release();
- m_pCurIter = NULL;
- }
-}
-void CFX_WordBreak::Release() {
- delete this;
-}
+
+CFX_WordBreak::CFX_WordBreak() {}
+
+CFX_WordBreak::~CFX_WordBreak() {}
+
void CFX_WordBreak::Attach(IFX_CharIter* pIter) {
ASSERT(pIter);
- m_pCurIter = pIter;
+ m_pCurIter.reset(pIter);
}
void CFX_WordBreak::Attach(const CFX_WideString& wsText) {
- m_pCurIter = new CFX_CharIter(wsText);
+ m_pCurIter.reset(new CFX_CharIter(wsText));
}
FX_BOOL CFX_WordBreak::Next(FX_BOOL bPrev) {
- IFX_CharIter* pIter = bPrev ? m_pPreIter->Clone() : m_pCurIter->Clone();
- if (pIter->IsEOF(!bPrev)) {
+ std::unique_ptr<IFX_CharIter> pIter(
+ (bPrev ? m_pPreIter : m_pCurIter)->Clone());
+ if (pIter->IsEOF(!bPrev))
return FALSE;
- }
+
pIter->Next(bPrev);
- if (!FindNextBreakPos(pIter, bPrev, TRUE)) {
- pIter->Release();
+ if (!FindNextBreakPos(pIter.get(), bPrev, TRUE))
return FALSE;
- }
+
if (bPrev) {
- m_pCurIter->Release();
- m_pCurIter = m_pPreIter;
+ m_pCurIter = std::move(m_pPreIter);
m_pCurIter->Next(TRUE);
- m_pPreIter = pIter;
+ m_pPreIter = std::move(pIter);
} else {
- m_pPreIter->Release();
- m_pPreIter = m_pCurIter;
+ m_pPreIter = std::move(m_pCurIter);
m_pPreIter->Next();
- m_pCurIter = pIter;
+ m_pCurIter = std::move(pIter);
}
return TRUE;
}
void CFX_WordBreak::SetAt(int32_t nIndex) {
- if (m_pPreIter) {
- m_pPreIter->Release();
- m_pPreIter = NULL;
- }
+ m_pPreIter.reset();
m_pCurIter->SetAt(nIndex);
- FindNextBreakPos(m_pCurIter, TRUE, FALSE);
- m_pPreIter = m_pCurIter;
- m_pCurIter = m_pPreIter->Clone();
- FindNextBreakPos(m_pCurIter, FALSE, FALSE);
+ FindNextBreakPos(m_pCurIter.get(), TRUE, FALSE);
+ m_pPreIter = std::move(m_pCurIter);
+ m_pCurIter.reset(m_pPreIter->Clone());
+ FindNextBreakPos(m_pCurIter.get(), FALSE, FALSE);
}
int32_t CFX_WordBreak::GetWordPos() const {
return m_pPreIter->GetAt();
@@ -121,16 +107,13 @@ void CFX_WordBreak::GetWord(CFX_WideString& wsWord) const {
return;
}
FX_WCHAR* lpBuf = wsWord.GetBuffer(nWordLength);
- IFX_CharIter* pTempIter = m_pPreIter->Clone();
+ std::unique_ptr<IFX_CharIter> pTempIter(m_pPreIter->Clone());
int32_t i = 0;
while (pTempIter->GetAt() <= m_pCurIter->GetAt()) {
lpBuf[i++] = pTempIter->GetChar();
- FX_BOOL bEnd = pTempIter->Next();
- if (!bEnd) {
+ if (!pTempIter->Next())
break;
- }
}
- pTempIter->Release();
wsWord.ReleaseBuffer(nWordLength);
}
FX_BOOL CFX_WordBreak::IsEOF(FX_BOOL bTail) const {
diff --git a/xfa/fee/ifde_txtedtengine.h b/xfa/fee/ifde_txtedtengine.h
index 1855f6f769..54e96b8c8f 100644
--- a/xfa/fee/ifde_txtedtengine.h
+++ b/xfa/fee/ifde_txtedtengine.h
@@ -142,7 +142,7 @@ struct FDE_TXTEDT_TEXTCHANGE_INFO {
class IFX_CharIter {
public:
virtual ~IFX_CharIter() {}
- virtual void Release() = 0;
+
virtual FX_BOOL Next(FX_BOOL bPrev = FALSE) = 0;
virtual FX_WCHAR GetChar() = 0;
virtual void SetAt(int32_t nIndex) = 0;