summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_streamcontentparser.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-21 16:22:10 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-21 16:22:10 -0800
commit06104a8abc71ecd824d6a461b6f6f31c32fd2135 (patch)
tree713f7dfacbdaec5e0ac25e8fe1d197a27453a725 /core/fpdfapi/page/cpdf_streamcontentparser.cpp
parentdc7ec035a6962b788e75f4beaa4cf8fbddd83d39 (diff)
downloadpdfium-06104a8abc71ecd824d6a461b6f6f31c32fd2135.tar.xz
Remove some WrapUnique() calls by returing unique_ptrs
Return these from underlying methods as appropriate. Review-Url: https://codereview.chromium.org/2520133002
Diffstat (limited to 'core/fpdfapi/page/cpdf_streamcontentparser.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp51
1 files changed, 26 insertions, 25 deletions
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 107ab1ccaa..8c6038d626 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -306,8 +306,8 @@ int CPDF_StreamContentParser::GetNextParamPos() {
if (m_ParamStartPos == kParamBufSize) {
m_ParamStartPos = 0;
}
- if (m_ParamBuf[m_ParamStartPos].m_Type == 0)
- delete m_ParamBuf[m_ParamStartPos].m_pObject;
+ if (m_ParamBuf[m_ParamStartPos].m_Type == ContentParam::OBJECT)
+ m_ParamBuf[m_ParamStartPos].m_pObject.reset();
return m_ParamStartPos;
}
@@ -324,8 +324,8 @@ void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) {
ContentParam& param = m_ParamBuf[GetNextParamPos()];
if (len > 32) {
param.m_Type = ContentParam::OBJECT;
- param.m_pObject =
- new CPDF_Name(m_pDocument->GetByteStringPool(), PDF_NameDecode(bsName));
+ param.m_pObject = pdfium::MakeUnique<CPDF_Name>(
+ m_pDocument->GetByteStringPool(), PDF_NameDecode(bsName));
} else {
param.m_Type = ContentParam::NAME;
if (bsName.Find('#') == -1) {
@@ -346,22 +346,21 @@ void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len) {
FX_atonum(CFX_ByteStringC(str, len), &param.m_Number.m_Integer);
}
-void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) {
+void CPDF_StreamContentParser::AddObjectParam(
+ std::unique_ptr<CPDF_Object> pObj) {
ContentParam& param = m_ParamBuf[GetNextParamPos()];
param.m_Type = ContentParam::OBJECT;
- param.m_pObject = pObj;
+ param.m_pObject = std::move(pObj);
}
void CPDF_StreamContentParser::ClearAllParams() {
uint32_t index = m_ParamStartPos;
for (uint32_t i = 0; i < m_ParamCount; i++) {
- if (m_ParamBuf[index].m_Type == 0)
- delete m_ParamBuf[index].m_pObject;
-
+ if (m_ParamBuf[index].m_Type == ContentParam::OBJECT)
+ m_ParamBuf[index].m_pObject.reset();
index++;
- if (index == kParamBufSize) {
+ if (index == kParamBufSize)
index = 0;
- }
}
m_ParamStartPos = 0;
m_ParamCount = 0;
@@ -377,25 +376,23 @@ CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) {
}
ContentParam& param = m_ParamBuf[real_index];
if (param.m_Type == ContentParam::NUMBER) {
- CPDF_Number* pNumber = param.m_Number.m_bInteger
- ? new CPDF_Number(param.m_Number.m_Integer)
- : new CPDF_Number(param.m_Number.m_Float);
-
param.m_Type = ContentParam::OBJECT;
- param.m_pObject = pNumber;
- return pNumber;
+ param.m_pObject =
+ param.m_Number.m_bInteger
+ ? pdfium::MakeUnique<CPDF_Number>(param.m_Number.m_Integer)
+ : pdfium::MakeUnique<CPDF_Number>(param.m_Number.m_Float);
+ return param.m_pObject.get();
}
if (param.m_Type == ContentParam::NAME) {
- CPDF_Name* pName = new CPDF_Name(
+ param.m_Type = ContentParam::OBJECT;
+ param.m_pObject = pdfium::MakeUnique<CPDF_Name>(
m_pDocument->GetByteStringPool(),
CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len));
- param.m_Type = ContentParam::OBJECT;
- param.m_pObject = pName;
- return pName;
- }
- if (param.m_Type == ContentParam::OBJECT) {
- return param.m_pObject;
+ return param.m_pObject.get();
}
+ if (param.m_Type == ContentParam::OBJECT)
+ return param.m_pObject.get();
+
ASSERT(false);
return nullptr;
}
@@ -651,7 +648,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() {
}
CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1,
m_pSyntax->GetWordSize() - 1);
- auto pObj = pdfium::WrapUnique(m_pSyntax->ReadNextObject(false, 0));
+ auto pObj = m_pSyntax->ReadNextObject(false, 0);
if (!key.IsEmpty()) {
uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0;
if (dwObjNum)
@@ -1668,3 +1665,7 @@ void CPDF_StreamContentParser::ParsePathObject() {
}
}
}
+
+CPDF_StreamContentParser::ContentParam::ContentParam() {}
+
+CPDF_StreamContentParser::ContentParam::~ContentParam() {}