GN: Use std::unique_ptr for owned pointers in ImportManager.
BUG=602726
Review URL: https://codereview.chromium.org/1886453002
Cr-Original-Commit-Position: refs/heads/master@{#387997}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 647a1af223628bb4e15b69a29ca257477282b737
diff --git a/tools/gn/import_manager.cc b/tools/gn/import_manager.cc
index 83cc090..8c57008 100644
--- a/tools/gn/import_manager.cc
+++ b/tools/gn/import_manager.cc
@@ -4,9 +4,6 @@
#include "tools/gn/import_manager.h"
-#include <memory>
-
-#include "base/stl_util.h"
#include "tools/gn/parse_tree.h"
#include "tools/gn/scheduler.h"
#include "tools/gn/scope_per_file_provider.h"
@@ -14,10 +11,10 @@
namespace {
// Returns a newly-allocated scope on success, null on failure.
-Scope* UncachedImport(const Settings* settings,
- const SourceFile& file,
- const ParseNode* node_for_err,
- Err* err) {
+std::unique_ptr<Scope> UncachedImport(const Settings* settings,
+ const SourceFile& file,
+ const ParseNode* node_for_err,
+ Err* err) {
const ParseNode* node = g_scheduler->input_file_manager()->SyncLoadFile(
node_for_err->GetRange(), settings->build_settings(), file, err);
if (!node)
@@ -37,7 +34,7 @@
return nullptr;
scope->ClearProcessingImport();
- return scope.release();
+ return scope;
}
} // namesapce
@@ -46,7 +43,6 @@
}
ImportManager::~ImportManager() {
- STLDeleteContainerPairSecondPointers(imports_.begin(), imports_.end());
}
bool ImportManager::DoImport(const SourceFile& file,
@@ -60,14 +56,14 @@
base::AutoLock lock(lock_);
ImportMap::const_iterator found = imports_.find(file);
if (found != imports_.end())
- imported_scope = found->second;
+ imported_scope = found->second.get();
}
if (!imported_scope) {
// Do a new import of the file.
- imported_scope = UncachedImport(scope->settings(), file,
- node_for_err, err);
- if (!imported_scope)
+ std::unique_ptr<Scope> new_imported_scope =
+ UncachedImport(scope->settings(), file, node_for_err, err);
+ if (!new_imported_scope)
return false;
// We loaded the file outside the lock. This means that there could be a
@@ -77,10 +73,10 @@
base::AutoLock lock(lock_);
ImportMap::const_iterator found = imports_.find(file);
if (found != imports_.end()) {
- delete imported_scope;
- imported_scope = found->second;
+ imported_scope = found->second.get();
} else {
- imports_[file] = imported_scope;
+ imported_scope = new_imported_scope.get();
+ imports_[file] = std::move(new_imported_scope);
}
}
}
diff --git a/tools/gn/import_manager.h b/tools/gn/import_manager.h
index 70aeee7..bd47a2a 100644
--- a/tools/gn/import_manager.h
+++ b/tools/gn/import_manager.h
@@ -6,6 +6,7 @@
#define TOOLS_GN_IMPORT_MANAGER_H_
#include <map>
+#include <memory>
#include "base/macros.h"
#include "base/synchronization/lock.h"
@@ -33,7 +34,7 @@
base::Lock lock_;
// Owning pointers to the scopes.
- typedef std::map<SourceFile, const Scope*> ImportMap;
+ typedef std::map<SourceFile, std::unique_ptr<const Scope>> ImportMap;
ImportMap imports_;
DISALLOW_COPY_AND_ASSIGN(ImportManager);