Convert pdfium::MakeUnique<> to std::make_unique<> in fxcrt
Use C++14 features.
-- ensure <memory> included in .cpp or corresponding .h file
-- remove ptr_util.h include unless WrapUnique() (0 cases).
Change-Id: Ic92ef71e68d6d29e3b455996cb2e8eacb8d67b42
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70030
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/cfx_fileaccess_posix.cpp b/core/fxcrt/cfx_fileaccess_posix.cpp
index f08df66..bf6c1b3 100644
--- a/core/fxcrt/cfx_fileaccess_posix.cpp
+++ b/core/fxcrt/cfx_fileaccess_posix.cpp
@@ -13,7 +13,6 @@
#include <memory>
#include "core/fxcrt/fx_stream.h"
-#include "third_party/base/ptr_util.h"
#ifndef O_BINARY
#define O_BINARY 0
@@ -43,7 +42,7 @@
// static
std::unique_ptr<FileAccessIface> FileAccessIface::Create() {
- return pdfium::MakeUnique<CFX_FileAccess_Posix>();
+ return std::make_unique<CFX_FileAccess_Posix>();
}
CFX_FileAccess_Posix::CFX_FileAccess_Posix() : m_nFD(-1) {}
diff --git a/core/fxcrt/cfx_fileaccess_windows.cpp b/core/fxcrt/cfx_fileaccess_windows.cpp
index d1e5ff1..e5043cb 100644
--- a/core/fxcrt/cfx_fileaccess_windows.cpp
+++ b/core/fxcrt/cfx_fileaccess_windows.cpp
@@ -10,7 +10,6 @@
#include "core/fxcrt/fx_stream.h"
#include "core/fxcrt/fx_string.h"
-#include "third_party/base/ptr_util.h"
namespace {
@@ -32,7 +31,7 @@
// static
std::unique_ptr<FileAccessIface> FileAccessIface::Create() {
- return pdfium::MakeUnique<CFX_FileAccess_Windows>();
+ return std::make_unique<CFX_FileAccess_Windows>();
}
CFX_FileAccess_Windows::CFX_FileAccess_Windows() : m_hFile(nullptr) {}
diff --git a/core/fxcrt/cfx_timer_unittest.cpp b/core/fxcrt/cfx_timer_unittest.cpp
index b95de72..5a7963f 100644
--- a/core/fxcrt/cfx_timer_unittest.cpp
+++ b/core/fxcrt/cfx_timer_unittest.cpp
@@ -9,7 +9,6 @@
#include "core/fxcrt/timerhandler_iface.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/base/ptr_util.h"
using testing::_;
using testing::DoAll;
@@ -45,8 +44,8 @@
MockTimerCallback cb2;
EXPECT_CALL(cb2, OnTimerFired()).Times(2);
- auto timer1 = pdfium::MakeUnique<CFX_Timer>(&scheduler, &cb1, 100);
- auto timer2 = pdfium::MakeUnique<CFX_Timer>(&scheduler, &cb2, 200);
+ auto timer1 = std::make_unique<CFX_Timer>(&scheduler, &cb1, 100);
+ auto timer2 = std::make_unique<CFX_Timer>(&scheduler, &cb2, 200);
EXPECT_TRUE(timer1->HasValidID());
EXPECT_TRUE(timer2->HasValidID());
@@ -70,7 +69,7 @@
EXPECT_CALL(cb1, OnTimerFired()).Times(0);
{
- auto timer1 = pdfium::MakeUnique<CFX_Timer>(&scheduler, &cb1, 100);
+ auto timer1 = std::make_unique<CFX_Timer>(&scheduler, &cb1, 100);
EXPECT_TRUE(timer1->HasValidID());
// Fire callback with bad arguments.
diff --git a/core/fxcrt/css/cfx_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp
index de97b64..057ffab 100644
--- a/core/fxcrt/css/cfx_cssdeclaration.cpp
+++ b/core/fxcrt/css/cfx_cssdeclaration.cpp
@@ -19,7 +19,6 @@
#include "core/fxcrt/css/cfx_cssvaluelistparser.h"
#include "core/fxcrt/fx_extension.h"
#include "third_party/base/logging.h"
-#include "third_party/base/ptr_util.h"
namespace {
@@ -157,7 +156,7 @@
void CFX_CSSDeclaration::AddPropertyHolder(CFX_CSSProperty eProperty,
RetainPtr<CFX_CSSValue> pValue,
bool bImportant) {
- auto pHolder = pdfium::MakeUnique<CFX_CSSPropertyHolder>();
+ auto pHolder = std::make_unique<CFX_CSSPropertyHolder>();
pHolder->bImportant = bImportant;
pHolder->eProperty = eProperty;
pHolder->pValue = pValue;
@@ -282,7 +281,7 @@
void CFX_CSSDeclaration::AddProperty(const WideString& prop,
const WideString& value) {
custom_properties_.push_back(
- pdfium::MakeUnique<CFX_CSSCustomProperty>(prop, value));
+ std::make_unique<CFX_CSSCustomProperty>(prop, value));
}
RetainPtr<CFX_CSSValue> CFX_CSSDeclaration::ParseNumber(const wchar_t* pszValue,
diff --git a/core/fxcrt/css/cfx_cssrulecollection.cpp b/core/fxcrt/css/cfx_cssrulecollection.cpp
index 4b63914..dcaba9a 100644
--- a/core/fxcrt/css/cfx_cssrulecollection.cpp
+++ b/core/fxcrt/css/cfx_cssrulecollection.cpp
@@ -14,7 +14,6 @@
#include "core/fxcrt/css/cfx_cssstylerule.h"
#include "core/fxcrt/css/cfx_cssstylesheet.h"
#include "core/fxcrt/css/cfx_csssyntaxparser.h"
-#include "third_party/base/ptr_util.h"
CFX_CSSRuleCollection::CFX_CSSRuleCollection() : m_iSelectors(0) {}
@@ -45,7 +44,7 @@
for (int32_t i = 0; i < iSelectors; ++i) {
CFX_CSSSelector* pSelector = pStyleRule->GetSelectorList(i);
m_TagRules[pSelector->GetNameHash()].push_back(
- pdfium::MakeUnique<Data>(pSelector, pDeclaration));
+ std::make_unique<Data>(pSelector, pDeclaration));
m_iSelectors++;
}
}
diff --git a/core/fxcrt/css/cfx_cssselector.cpp b/core/fxcrt/css/cfx_cssselector.cpp
index cd90f62..492ec2e 100644
--- a/core/fxcrt/css/cfx_cssselector.cpp
+++ b/core/fxcrt/css/cfx_cssselector.cpp
@@ -9,7 +9,6 @@
#include <utility>
#include "core/fxcrt/fx_extension.h"
-#include "third_party/base/ptr_util.h"
namespace {
@@ -69,8 +68,8 @@
wchar_t wch = *psz;
if ((isascii(wch) && isalpha(wch)) || wch == '*') {
int32_t iNameLen = wch == '*' ? 1 : GetCSSNameLen(psz, pEnd);
- auto p = pdfium::MakeUnique<CFX_CSSSelector>(CFX_CSSSelectorType::Element,
- psz, iNameLen, true);
+ auto p = std::make_unique<CFX_CSSSelector>(CFX_CSSSelectorType::Element,
+ psz, iNameLen, true);
if (pFirst) {
pFirst->SetType(CFX_CSSSelectorType::Descendant);
p->SetNext(std::move(pFirst));
diff --git a/core/fxcrt/css/cfx_cssstyleselector.cpp b/core/fxcrt/css/cfx_cssstyleselector.cpp
index 998424d..c13aca6 100644
--- a/core/fxcrt/css/cfx_cssstyleselector.cpp
+++ b/core/fxcrt/css/cfx_cssstyleselector.cpp
@@ -20,7 +20,6 @@
#include "core/fxcrt/css/cfx_csssyntaxparser.h"
#include "core/fxcrt/css/cfx_cssvaluelist.h"
#include "third_party/base/logging.h"
-#include "third_party/base/ptr_util.h"
CFX_CSSStyleSelector::CFX_CSSStyleSelector() : m_fDefFontSize(12.0f) {}
@@ -85,7 +84,7 @@
CFX_CSSComputedStyle* pDest) {
std::unique_ptr<CFX_CSSDeclaration> pDecl;
if (!styleString.IsEmpty() || !alignString.IsEmpty()) {
- pDecl = pdfium::MakeUnique<CFX_CSSDeclaration>();
+ pDecl = std::make_unique<CFX_CSSDeclaration>();
if (!styleString.IsEmpty())
AppendInlineStyle(pDecl.get(), styleString);
@@ -142,7 +141,7 @@
ASSERT(pDecl);
ASSERT(!style.IsEmpty());
- auto pSyntax = pdfium::MakeUnique<CFX_CSSSyntaxParser>(style.AsStringView());
+ auto pSyntax = std::make_unique<CFX_CSSSyntaxParser>(style.AsStringView());
pSyntax->SetParseOnlyDeclarations();
int32_t iLen2 = 0;
diff --git a/core/fxcrt/css/cfx_cssstylesheet.cpp b/core/fxcrt/css/cfx_cssstylesheet.cpp
index 23b0514..fc0591a 100644
--- a/core/fxcrt/css/cfx_cssstylesheet.cpp
+++ b/core/fxcrt/css/cfx_cssstylesheet.cpp
@@ -12,9 +12,8 @@
#include "core/fxcrt/css/cfx_cssdeclaration.h"
#include "core/fxcrt/css/cfx_cssstylerule.h"
#include "core/fxcrt/fx_codepage.h"
-#include "third_party/base/ptr_util.h"
-CFX_CSSStyleSheet::CFX_CSSStyleSheet() {}
+CFX_CSSStyleSheet::CFX_CSSStyleSheet() = default;
CFX_CSSStyleSheet::~CFX_CSSStyleSheet() = default;
@@ -28,7 +27,7 @@
bool CFX_CSSStyleSheet::LoadBuffer(WideStringView buffer) {
m_RuleArray.clear();
- auto pSyntax = pdfium::MakeUnique<CFX_CSSSyntaxParser>(buffer);
+ auto pSyntax = std::make_unique<CFX_CSSSyntaxParser>(buffer);
while (1) {
CFX_CSSSyntaxStatus eStatus = pSyntax->DoSyntaxParse();
if (eStatus == CFX_CSSSyntaxStatus::kStyleRule)
@@ -80,7 +79,7 @@
}
case CFX_CSSSyntaxStatus::kDeclOpen: {
if (!pStyleRule && !selectors.empty()) {
- auto rule = pdfium::MakeUnique<CFX_CSSStyleRule>();
+ auto rule = std::make_unique<CFX_CSSStyleRule>();
pStyleRule = rule.get();
pStyleRule->SetSelector(&selectors);
m_RuleArray.push_back(std::move(rule));
diff --git a/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp b/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp
index 2c94470..082d2ac 100644
--- a/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp
+++ b/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp
@@ -15,13 +15,12 @@
#include "core/fxcrt/css/cfx_cssstylerule.h"
#include "core/fxcrt/css/cfx_cssvaluelist.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
class CFX_CSSStyleSheetTest : public testing::Test {
public:
void SetUp() override {
- sheet_ = pdfium::MakeUnique<CFX_CSSStyleSheet>();
+ sheet_ = std::make_unique<CFX_CSSStyleSheet>();
decl_ = nullptr;
}
diff --git a/core/fxcrt/css/cfx_cssvaluelistparser_unittest.cpp b/core/fxcrt/css/cfx_cssvaluelistparser_unittest.cpp
index bb065f8..12765ef 100644
--- a/core/fxcrt/css/cfx_cssvaluelistparser_unittest.cpp
+++ b/core/fxcrt/css/cfx_cssvaluelistparser_unittest.cpp
@@ -6,34 +6,35 @@
#include "core/fxcrt/css/cfx_cssvaluelistparser.h"
+#include <memory>
+
#include "core/fxcrt/widestring.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/base/ptr_util.h"
TEST(CFX_CSSValueListParserTest, rgb_short) {
CFX_CSSPrimitiveType type;
const wchar_t* start;
int32_t len;
- auto parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"#abc", 4, L' ');
+ auto parser = std::make_unique<CFX_CSSValueListParser>(L"#abc", 4, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::RGB, type);
EXPECT_EQ(L"#abc", WideString(start, len));
EXPECT_FALSE(parser->NextValue(&type, &start, &len));
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"#abcdef", 7, L' ');
+ parser = std::make_unique<CFX_CSSValueListParser>(L"#abcdef", 7, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::RGB, type);
EXPECT_EQ(L"#abcdef", WideString(start, len));
EXPECT_FALSE(parser->NextValue(&type, &start, &len));
parser =
- pdfium::MakeUnique<CFX_CSSValueListParser>(L"rgb(1, 255, 4)", 14, L' ');
+ std::make_unique<CFX_CSSValueListParser>(L"rgb(1, 255, 4)", 14, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::RGB, type);
EXPECT_EQ(L"rgb(1, 255, 4)", WideString(start, len));
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"#abcdefghij", 11, L' ');
+ parser = std::make_unique<CFX_CSSValueListParser>(L"#abcdefghij", 11, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::Unknown, type);
EXPECT_EQ(L"#abcdefghij", WideString(start, len));
@@ -45,38 +46,38 @@
const wchar_t* start;
int32_t len;
- auto parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"1234", 4, L' ');
+ auto parser = std::make_unique<CFX_CSSValueListParser>(L"1234", 4, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::Number, type);
EXPECT_EQ(L"1234", WideString(start, len));
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"-1234", 5, L' ');
+ parser = std::make_unique<CFX_CSSValueListParser>(L"-1234", 5, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::Number, type);
EXPECT_EQ(L"-1234", WideString(start, len));
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"+1234", 5, L' ');
+ parser = std::make_unique<CFX_CSSValueListParser>(L"+1234", 5, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::Number, type);
EXPECT_EQ(L"+1234", WideString(start, len));
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L".1234", 5, L' ');
+ parser = std::make_unique<CFX_CSSValueListParser>(L".1234", 5, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::Number, type);
EXPECT_EQ(L".1234", WideString(start, len));
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"4321.1234", 9, L' ');
+ parser = std::make_unique<CFX_CSSValueListParser>(L"4321.1234", 9, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::Number, type);
EXPECT_EQ(L"4321.1234", WideString(start, len));
// TODO(dsinclair): These should probably fail but currently don't.
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"4321.12.34", 10, L' ');
+ parser = std::make_unique<CFX_CSSValueListParser>(L"4321.12.34", 10, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::Number, type);
EXPECT_EQ(L"4321.12.34", WideString(start, len));
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"43a1.12.34", 10, L' ');
+ parser = std::make_unique<CFX_CSSValueListParser>(L"43a1.12.34", 10, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::Number, type);
EXPECT_EQ(L"43a1.12.34", WideString(start, len));
@@ -87,19 +88,18 @@
const wchar_t* start;
int32_t len;
- auto parser =
- pdfium::MakeUnique<CFX_CSSValueListParser>(L"'string'", 8, L' ');
+ auto parser = std::make_unique<CFX_CSSValueListParser>(L"'string'", 8, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::String, type);
EXPECT_EQ(L"string", WideString(start, len));
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"\"another string\"", 16,
- L' ');
+ parser =
+ std::make_unique<CFX_CSSValueListParser>(L"\"another string\"", 16, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::String, type);
EXPECT_EQ(L"another string", WideString(start, len));
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"standalone", 10, L' ');
+ parser = std::make_unique<CFX_CSSValueListParser>(L"standalone", 10, L' ');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::String, type);
EXPECT_EQ(L"standalone", WideString(start, len));
@@ -110,7 +110,7 @@
const wchar_t* start;
int32_t len;
- auto parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"1, 2, 3", 7, L',');
+ auto parser = std::make_unique<CFX_CSSValueListParser>(L"1, 2, 3", 7, L',');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::Number, type);
EXPECT_EQ(L"1", WideString(start, len));
@@ -125,8 +125,8 @@
EXPECT_FALSE(parser->NextValue(&type, &start, &len));
- parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"'str', rgb(1, 2, 3), 4",
- 22, L',');
+ parser = std::make_unique<CFX_CSSValueListParser>(L"'str', rgb(1, 2, 3), 4",
+ 22, L',');
EXPECT_TRUE(parser->NextValue(&type, &start, &len));
EXPECT_EQ(CFX_CSSPrimitiveType::String, type);
EXPECT_EQ(L"str", WideString(start, len));
diff --git a/core/fxcrt/maybe_owned_unittest.cpp b/core/fxcrt/maybe_owned_unittest.cpp
index 53cab6c..b0e5890 100644
--- a/core/fxcrt/maybe_owned_unittest.cpp
+++ b/core/fxcrt/maybe_owned_unittest.cpp
@@ -9,7 +9,6 @@
#include "core/fxcrt/unowned_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/base/ptr_util.h"
namespace fxcrt {
namespace {
@@ -72,7 +71,7 @@
{
MaybeOwned<PseudoDeletable> ptr(&thing1);
EXPECT_EQ(100, ptr->GetID());
- ptr = pdfium::MakeUnique<PseudoDeletable>(300, &owned_delete_count);
+ ptr = std::make_unique<PseudoDeletable>(300, &owned_delete_count);
EXPECT_TRUE(ptr.IsOwned());
EXPECT_EQ(300, ptr->GetID());
}
@@ -99,7 +98,7 @@
int delete_count = 0;
{
MaybeOwned<PseudoDeletable> ptr(
- pdfium::MakeUnique<PseudoDeletable>(100, &delete_count));
+ std::make_unique<PseudoDeletable>(100, &delete_count));
EXPECT_TRUE(ptr.IsOwned());
EXPECT_EQ(100, ptr->GetID());
@@ -112,8 +111,8 @@
delete_count = 0;
{
MaybeOwned<PseudoDeletable> ptr(
- pdfium::MakeUnique<PseudoDeletable>(200, &delete_count));
- ptr = pdfium::MakeUnique<PseudoDeletable>(300, &delete_count);
+ std::make_unique<PseudoDeletable>(200, &delete_count));
+ ptr = std::make_unique<PseudoDeletable>(300, &delete_count);
EXPECT_TRUE(ptr.IsOwned());
EXPECT_EQ(300, ptr->GetID());
EXPECT_EQ(1, delete_count);
@@ -125,7 +124,7 @@
PseudoDeletable thing2(400, &unowned_delete_count);
{
MaybeOwned<PseudoDeletable> ptr(
- pdfium::MakeUnique<PseudoDeletable>(500, &delete_count));
+ std::make_unique<PseudoDeletable>(500, &delete_count));
ptr = &thing2;
EXPECT_FALSE(ptr.IsOwned());
EXPECT_EQ(400, ptr->GetID());
@@ -142,7 +141,7 @@
std::unique_ptr<PseudoDeletable> stolen;
{
MaybeOwned<PseudoDeletable> ptr(
- pdfium::MakeUnique<PseudoDeletable>(100, &delete_count));
+ std::make_unique<PseudoDeletable>(100, &delete_count));
EXPECT_TRUE(ptr.IsOwned());
stolen = ptr.Release();
EXPECT_FALSE(ptr.IsOwned());
@@ -160,7 +159,7 @@
{
MaybeOwned<PseudoDeletable> ptr1(&thing1);
MaybeOwned<PseudoDeletable> ptr2(
- pdfium::MakeUnique<PseudoDeletable>(200, &delete_count));
+ std::make_unique<PseudoDeletable>(200, &delete_count));
EXPECT_FALSE(ptr1.IsOwned());
EXPECT_TRUE(ptr2.IsOwned());
diff --git a/core/fxcrt/observed_ptr_unittest.cpp b/core/fxcrt/observed_ptr_unittest.cpp
index 81e114f..07b2b1a 100644
--- a/core/fxcrt/observed_ptr_unittest.cpp
+++ b/core/fxcrt/observed_ptr_unittest.cpp
@@ -4,11 +4,11 @@
#include "core/fxcrt/observed_ptr.h"
+#include <memory>
#include <utility>
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/base/ptr_util.h"
namespace fxcrt {
namespace {
@@ -34,7 +34,7 @@
TEST(ObservePtr, LivesLonger) {
ObservedPtr<PseudoObservable> ptr;
{
- auto pObs = pdfium::MakeUnique<PseudoObservable>();
+ auto pObs = std::make_unique<PseudoObservable>();
ptr.Reset(pObs.get());
EXPECT_NE(nullptr, ptr.Get());
EXPECT_EQ(1u, pObs->ActiveObservedPtrs());
diff --git a/core/fxcrt/retain_ptr.h b/core/fxcrt/retain_ptr.h
index 1bbd96a..2598f1d 100644
--- a/core/fxcrt/retain_ptr.h
+++ b/core/fxcrt/retain_ptr.h
@@ -153,10 +153,10 @@
namespace pdfium {
-// Helper to make a RetainPtr along the lines of std::make_unique<>(),
-// or pdfium::MakeUnique<>(). Arguments are forwarded to T's constructor.
-// Classes managed by RetainPtr should have protected (or private)
-// constructors, and should friend this function.
+// Helper to make a RetainPtr along the lines of std::make_unique<>().
+// Arguments are forwarded to T's constructor. Classes managed by RetainPtr
+// should have protected (or private) constructors, and should friend this
+// function.
template <typename T, typename... Args>
RetainPtr<T> MakeRetain(Args&&... args) {
return RetainPtr<T>(new T(std::forward<Args>(args)...));
diff --git a/core/fxcrt/tree_node_unittest.cpp b/core/fxcrt/tree_node_unittest.cpp
index 26dd610..ce82bce 100644
--- a/core/fxcrt/tree_node_unittest.cpp
+++ b/core/fxcrt/tree_node_unittest.cpp
@@ -7,7 +7,6 @@
#include <memory>
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/base/ptr_util.h"
namespace fxcrt {
@@ -17,59 +16,59 @@
// These tests check that we trip CHECKS given bad calls.
TEST(TreeNode, SelfAppendFirstChild) {
- auto pNode = pdfium::MakeUnique<TestTreeNode>();
+ auto pNode = std::make_unique<TestTreeNode>();
EXPECT_DEATH(pNode->AppendFirstChild(pNode.get()), "");
}
TEST(TreeNode, SelfAppendLastChild) {
- auto pNode = pdfium::MakeUnique<TestTreeNode>();
+ auto pNode = std::make_unique<TestTreeNode>();
EXPECT_DEATH(pNode->AppendLastChild(pNode.get()), "");
}
TEST(TreeNode, SelfInsertBeforeOther) {
- auto pNode = pdfium::MakeUnique<TestTreeNode>();
- auto pOther = pdfium::MakeUnique<TestTreeNode>();
+ auto pNode = std::make_unique<TestTreeNode>();
+ auto pOther = std::make_unique<TestTreeNode>();
pNode->AppendFirstChild(pOther.get());
EXPECT_DEATH(pNode->InsertBefore(pNode.get(), pOther.get()), "");
}
TEST(TreeNode, InsertOtherBeforeSelf) {
- auto pNode = pdfium::MakeUnique<TestTreeNode>();
- auto pOther = pdfium::MakeUnique<TestTreeNode>();
+ auto pNode = std::make_unique<TestTreeNode>();
+ auto pOther = std::make_unique<TestTreeNode>();
pNode->AppendFirstChild(pOther.get());
EXPECT_DEATH(pNode->InsertBefore(pOther.get(), pNode.get()), "");
}
TEST(TreeNode, SelfInsertAfterOther) {
- auto pNode = pdfium::MakeUnique<TestTreeNode>();
- auto pOther = pdfium::MakeUnique<TestTreeNode>();
+ auto pNode = std::make_unique<TestTreeNode>();
+ auto pOther = std::make_unique<TestTreeNode>();
pNode->AppendFirstChild(pOther.get());
EXPECT_DEATH(pNode->InsertBefore(pNode.get(), pOther.get()), "");
}
TEST(TreeNode, InsertOtherAfterSelf) {
- auto pNode = pdfium::MakeUnique<TestTreeNode>();
- auto pOther = pdfium::MakeUnique<TestTreeNode>();
+ auto pNode = std::make_unique<TestTreeNode>();
+ auto pOther = std::make_unique<TestTreeNode>();
pNode->AppendFirstChild(pOther.get());
EXPECT_DEATH(pNode->InsertBefore(pOther.get(), pNode.get()), "");
}
TEST(TreeNode, RemoveParentless) {
- auto pNode = pdfium::MakeUnique<TestTreeNode>();
+ auto pNode = std::make_unique<TestTreeNode>();
EXPECT_DEATH(pNode->GetParent()->RemoveChild(pNode.get()), "");
}
TEST(TreeNode, RemoveFromWrongParent) {
- auto pGoodParent = pdfium::MakeUnique<TestTreeNode>();
- auto pBadParent = pdfium::MakeUnique<TestTreeNode>();
- auto pNode = pdfium::MakeUnique<TestTreeNode>();
+ auto pGoodParent = std::make_unique<TestTreeNode>();
+ auto pBadParent = std::make_unique<TestTreeNode>();
+ auto pNode = std::make_unique<TestTreeNode>();
pGoodParent->AppendFirstChild(pNode.get());
EXPECT_DEATH(pBadParent->RemoveChild(pNode.get()), "");
}
TEST(TreeNode, SafeRemove) {
- auto pParent = pdfium::MakeUnique<TestTreeNode>();
- auto pChild = pdfium::MakeUnique<TestTreeNode>();
+ auto pParent = std::make_unique<TestTreeNode>();
+ auto pChild = std::make_unique<TestTreeNode>();
pParent->AppendFirstChild(pChild.get());
pChild->RemoveSelfIfParented();
EXPECT_EQ(nullptr, pParent->GetFirstChild());
@@ -77,20 +76,20 @@
}
TEST(TreeNode, SafeRemoveParentless) {
- auto pNode = pdfium::MakeUnique<TestTreeNode>();
+ auto pNode = std::make_unique<TestTreeNode>();
pNode->RemoveSelfIfParented();
EXPECT_EQ(nullptr, pNode->GetParent());
}
TEST(TreeNode, RemoveAllChildren) {
- auto pParent = pdfium::MakeUnique<TestTreeNode>();
+ auto pParent = std::make_unique<TestTreeNode>();
pParent->RemoveAllChildren();
EXPECT_EQ(nullptr, pParent->GetFirstChild());
- auto p0 = pdfium::MakeUnique<TestTreeNode>();
- auto p1 = pdfium::MakeUnique<TestTreeNode>();
- auto p2 = pdfium::MakeUnique<TestTreeNode>();
- auto p3 = pdfium::MakeUnique<TestTreeNode>();
+ auto p0 = std::make_unique<TestTreeNode>();
+ auto p1 = std::make_unique<TestTreeNode>();
+ auto p2 = std::make_unique<TestTreeNode>();
+ auto p3 = std::make_unique<TestTreeNode>();
pParent->AppendLastChild(p0.get());
pParent->AppendLastChild(p1.get());
pParent->AppendLastChild(p2.get());
@@ -100,14 +99,14 @@
}
TEST(TreeNode, NthChild) {
- auto pParent = pdfium::MakeUnique<TestTreeNode>();
+ auto pParent = std::make_unique<TestTreeNode>();
EXPECT_EQ(nullptr, pParent->GetNthChild(-1));
EXPECT_EQ(nullptr, pParent->GetNthChild(0));
- auto p0 = pdfium::MakeUnique<TestTreeNode>();
- auto p1 = pdfium::MakeUnique<TestTreeNode>();
- auto p2 = pdfium::MakeUnique<TestTreeNode>();
- auto p3 = pdfium::MakeUnique<TestTreeNode>();
+ auto p0 = std::make_unique<TestTreeNode>();
+ auto p1 = std::make_unique<TestTreeNode>();
+ auto p2 = std::make_unique<TestTreeNode>();
+ auto p3 = std::make_unique<TestTreeNode>();
pParent->AppendLastChild(p0.get());
pParent->AppendLastChild(p1.get());
pParent->AppendLastChild(p2.get());
@@ -122,9 +121,9 @@
}
TEST(TreeNode, AppendFirstChild) {
- auto parent = pdfium::MakeUnique<TestTreeNode>();
- auto child0 = pdfium::MakeUnique<TestTreeNode>();
- auto child1 = pdfium::MakeUnique<TestTreeNode>();
+ auto parent = std::make_unique<TestTreeNode>();
+ auto child0 = std::make_unique<TestTreeNode>();
+ auto child1 = std::make_unique<TestTreeNode>();
parent->AppendFirstChild(child0.get());
EXPECT_EQ(child0.get(), parent->GetFirstChild());
parent->AppendFirstChild(child1.get());
@@ -134,9 +133,9 @@
}
TEST(TreeNode, RemoveChild) {
- auto parent = pdfium::MakeUnique<TestTreeNode>();
- auto child0 = pdfium::MakeUnique<TestTreeNode>();
- auto child1 = pdfium::MakeUnique<TestTreeNode>();
+ auto parent = std::make_unique<TestTreeNode>();
+ auto child0 = std::make_unique<TestTreeNode>();
+ auto child1 = std::make_unique<TestTreeNode>();
parent->AppendFirstChild(child0.get());
parent->AppendLastChild(child1.get());
diff --git a/core/fxcrt/unowned_ptr_unittest.cpp b/core/fxcrt/unowned_ptr_unittest.cpp
index fa884d4..26fc542 100644
--- a/core/fxcrt/unowned_ptr_unittest.cpp
+++ b/core/fxcrt/unowned_ptr_unittest.cpp
@@ -8,7 +8,6 @@
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/base/ptr_util.h"
namespace fxcrt {
namespace {
@@ -19,35 +18,35 @@
};
void DeleteDangling() {
- auto ptr2 = pdfium::MakeUnique<Clink>();
+ auto ptr2 = std::make_unique<Clink>();
{
- auto ptr1 = pdfium::MakeUnique<Clink>();
+ auto ptr1 = std::make_unique<Clink>();
ptr2->next_ = ptr1.get();
}
}
void ResetDangling() {
- auto ptr2 = pdfium::MakeUnique<Clink>();
+ auto ptr2 = std::make_unique<Clink>();
{
- auto ptr1 = pdfium::MakeUnique<Clink>();
+ auto ptr1 = std::make_unique<Clink>();
ptr2->next_.Reset(ptr1.get());
}
ptr2->next_.Reset();
}
void AssignDangling() {
- auto ptr2 = pdfium::MakeUnique<Clink>();
+ auto ptr2 = std::make_unique<Clink>();
{
- auto ptr1 = pdfium::MakeUnique<Clink>();
+ auto ptr1 = std::make_unique<Clink>();
ptr2->next_ = ptr1.get();
}
ptr2->next_ = nullptr;
}
void ReleaseDangling() {
- auto ptr2 = pdfium::MakeUnique<Clink>();
+ auto ptr2 = std::make_unique<Clink>();
{
- auto ptr1 = pdfium::MakeUnique<Clink>();
+ auto ptr1 = std::make_unique<Clink>();
ptr2->next_ = ptr1.get();
}
ptr2->next_.Release();
@@ -56,9 +55,9 @@
} // namespace
TEST(UnownedPtr, PtrOk) {
- auto ptr1 = pdfium::MakeUnique<Clink>();
+ auto ptr1 = std::make_unique<Clink>();
{
- auto ptr2 = pdfium::MakeUnique<Clink>();
+ auto ptr2 = std::make_unique<Clink>();
ptr2->next_ = ptr1.get();
}
}
@@ -72,9 +71,9 @@
}
TEST(UnownedPtr, ResetOk) {
- auto ptr1 = pdfium::MakeUnique<Clink>();
+ auto ptr1 = std::make_unique<Clink>();
{
- auto ptr2 = pdfium::MakeUnique<Clink>();
+ auto ptr2 = std::make_unique<Clink>();
ptr2->next_.Reset(ptr1.get());
ptr2->next_.Reset(nullptr);
}
@@ -89,9 +88,9 @@
}
TEST(UnownedPtr, AssignOk) {
- auto ptr1 = pdfium::MakeUnique<Clink>();
+ auto ptr1 = std::make_unique<Clink>();
{
- auto ptr2 = pdfium::MakeUnique<Clink>();
+ auto ptr2 = std::make_unique<Clink>();
ptr2->next_ = ptr1.get();
ptr2->next_ = nullptr;
}
@@ -106,9 +105,9 @@
}
TEST(UnownedPtr, ReleaseOk) {
- auto ptr2 = pdfium::MakeUnique<Clink>();
+ auto ptr2 = std::make_unique<Clink>();
{
- auto ptr1 = pdfium::MakeUnique<Clink>();
+ auto ptr1 = std::make_unique<Clink>();
ptr2->next_ = ptr1.get();
ptr2->next_.Release();
}
@@ -117,7 +116,7 @@
TEST(UnownedPtr, MoveCtorOk) {
UnownedPtr<Clink> outer;
{
- auto owned = pdfium::MakeUnique<Clink>();
+ auto owned = std::make_unique<Clink>();
outer = owned.get();
UnownedPtr<Clink> inner(std::move(outer));
EXPECT_EQ(nullptr, outer.Get());
@@ -127,7 +126,7 @@
TEST(UnownedPtr, MoveAssignOk) {
UnownedPtr<Clink> outer;
{
- auto owned = pdfium::MakeUnique<Clink>();
+ auto owned = std::make_unique<Clink>();
outer = owned.get();
UnownedPtr<Clink> inner;
inner = std::move(outer);
diff --git a/core/fxcrt/xml/cfx_xmldocument.h b/core/fxcrt/xml/cfx_xmldocument.h
index 9931314..51634db 100644
--- a/core/fxcrt/xml/cfx_xmldocument.h
+++ b/core/fxcrt/xml/cfx_xmldocument.h
@@ -11,7 +11,6 @@
#include "core/fxcrt/unowned_ptr.h"
#include "core/fxcrt/xml/cfx_xmlelement.h"
-#include "third_party/base/ptr_util.h"
class CFX_XMLNode;
@@ -24,7 +23,7 @@
template <typename T, typename... Args>
T* CreateNode(Args&&... args) {
- nodes_.push_back(pdfium::MakeUnique<T>(std::forward<Args>(args)...));
+ nodes_.push_back(std::make_unique<T>(std::forward<Args>(args)...));
return static_cast<T*>(nodes_.back().get());
}
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index 9393bbd..28958ba 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -22,7 +22,6 @@
#include "core/fxcrt/xml/cfx_xmlinstruction.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"
#include "core/fxcrt/xml/cfx_xmltext.h"
-#include "third_party/base/ptr_util.h"
namespace {
@@ -80,7 +79,7 @@
CFX_XMLParser::~CFX_XMLParser() = default;
std::unique_ptr<CFX_XMLDocument> CFX_XMLParser::Parse() {
- auto doc = pdfium::MakeUnique<CFX_XMLDocument>();
+ auto doc = std::make_unique<CFX_XMLDocument>();
current_node_ = doc->GetRoot();
return DoSyntaxParse(doc.get()) ? std::move(doc) : nullptr;