Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Unified Diff: tools/gn/scope.cc

Issue 1885513003: GN: Use std::unique_ptr for owning pointers in Scope::NamedScopeMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/scope.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/scope.cc
diff --git a/tools/gn/scope.cc b/tools/gn/scope.cc
index d3d29d44927ca7d1a6105d24cbeaf008560a177d..93ce966e4f3e8abfcb0bc20ce9e7a374ed56f9a5 100644
--- a/tools/gn/scope.cc
+++ b/tools/gn/scope.cc
@@ -5,7 +5,7 @@
#include "tools/gn/scope.h"
#include "base/logging.h"
-#include "base/stl_util.h"
+#include "base/memory/ptr_util.h"
#include "tools/gn/parse_tree.h"
#include "tools/gn/template.h"
@@ -64,8 +64,6 @@ Scope::Scope(const Scope* parent)
}
Scope::~Scope() {
- STLDeleteContainerPairSecondPointers(target_defaults_.begin(),
- target_defaults_.end());
}
const Value* Scope::GetValue(const base::StringPiece& ident,
@@ -315,12 +313,9 @@ bool Scope::NonRecursiveMergeTo(Scope* dest,
}
}
- // Be careful to delete any pointer we're about to clobber.
- Scope** dest_scope = &dest->target_defaults_[current_name];
- if (*dest_scope)
- delete *dest_scope;
- *dest_scope = new Scope(settings_);
- pair.second->NonRecursiveMergeTo(*dest_scope, options, node_for_err,
+ std::unique_ptr<Scope>& dest_scope = dest->target_defaults_[current_name];
+ dest_scope = base::WrapUnique(new Scope(settings_));
+ pair.second->NonRecursiveMergeTo(dest_scope.get(), options, node_for_err,
"<SHOULDN'T HAPPEN>", err);
}
@@ -412,19 +407,19 @@ Scope* Scope::MakeTargetDefaults(const std::string& target_type) {
if (GetTargetDefaults(target_type))
return nullptr;
- Scope** dest = &target_defaults_[target_type];
- if (*dest) {
+ std::unique_ptr<Scope>& dest = target_defaults_[target_type];
+ if (dest) {
NOTREACHED(); // Already set.
- return *dest;
+ return dest.get();
}
- *dest = new Scope(settings_);
- return *dest;
+ dest = base::WrapUnique(new Scope(settings_));
+ return dest.get();
}
const Scope* Scope::GetTargetDefaults(const std::string& target_type) const {
NamedScopeMap::const_iterator found = target_defaults_.find(target_type);
if (found != target_defaults_.end())
- return found->second;
+ return found->second.get();
if (containing())
return containing()->GetTargetDefaults(target_type);
return nullptr;
« no previous file with comments | « tools/gn/scope.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698