From 8482575d1f15f13b7819856a4bc89f5035964799 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 29 Mar 2015 19:08:31 +0800 Subject: [PATCH] Don't store args as std::string --- atom/app/atom_main.cc | 2 +- atom/app/atom_main_args.cc | 16 +++++++++------- atom/app/atom_main_args.h | 10 +++++----- atom/common/node_bindings.cc | 19 +------------------ 4 files changed, 16 insertions(+), 31 deletions(-) diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc index 02dc985e30c4..2da9319dfbbc 100644 --- a/atom/app/atom_main.cc +++ b/atom/app/atom_main.cc @@ -155,7 +155,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { content::ContentMainParams params(&delegate); params.instance = instance; params.sandbox_info = &sandbox_info; - atom::AtomCommandLine::Init(argc, argv); + atom::AtomCommandLine::Init(argc, const_cast(argv)); return content::ContentMain(params); } diff --git a/atom/app/atom_main_args.cc b/atom/app/atom_main_args.cc index fb04ce5e735c..00039f0346a4 100644 --- a/atom/app/atom_main_args.cc +++ b/atom/app/atom_main_args.cc @@ -6,13 +6,15 @@ namespace atom { - void AtomCommandLine::Init(int argc, - const char* const* argv) { - for (int i = 0; i < argc; ++i) { - argv_.push_back(argv[i]); - } - } +// static +std::vector AtomCommandLine::argv_; - std::vector AtomCommandLine::argv_; +// static +void AtomCommandLine::Init(int argc, const char* argv[]) { + argv_.reserve(argc); + for (int i = 0; i < argc; ++i) { + argv_.push_back(argv[i]); + } +} } // namespace atom diff --git a/atom/app/atom_main_args.h b/atom/app/atom_main_args.h index db34b4ed05b5..3d6db95f776d 100644 --- a/atom/app/atom_main_args.h +++ b/atom/app/atom_main_args.h @@ -5,22 +5,22 @@ #ifndef ATOM_APP_ATOM_MAIN_ARGS_H_ #define ATOM_APP_ATOM_MAIN_ARGS_H_ -#include #include #include "base/logging.h" namespace atom { +// Singleton to remember the original "argc" and "argv". class AtomCommandLine { public: - static void Init(int argc, const char* const* argv); - static std::vector argv() { return argv_; } + static void Init(int argc, const char* argv[]); + static std::vector argv() { return argv_; } private: - static std::vector argv_; + static std::vector argv_; - DISALLOW_COPY_AND_ASSIGN(AtomCommandLine); + DISALLOW_IMPLICIT_CONSTRUCTORS(AtomCommandLine); }; } // namespace atom diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index 2503bb6175b5..ce00c5d38888 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -18,10 +18,6 @@ #include "native_mate/locker.h" #include "native_mate/dictionary.h" -#if defined(OS_WIN) -#include "base/strings/utf_string_conversions.h" -#endif - #include "atom/common/node_includes.h" using content::BrowserThread; @@ -92,18 +88,6 @@ namespace { void UvNoOp(uv_async_t* handle) { } -// Convert the given vector to an array of C-strings. The strings in the -// returned vector are only guaranteed valid so long as the vector of strings -// is not modified. -scoped_ptr StringVectorToArgArray( - const std::vector& vector) { - scoped_ptr array(new const char*[vector.size()]); - for (size_t i = 0; i < vector.size(); ++i) { - array[i] = vector[i].c_str(); - } - return array.Pass(); -} - base::FilePath GetResourcesPath(base::CommandLine* command_line, bool is_browser) { base::FilePath exec_path(command_line->argv()[0]); @@ -173,10 +157,9 @@ node::Environment* NodeBindings::CreateEnvironment( std::string script_path_str = script_path.AsUTF8Unsafe(); args.insert(args.begin() + 1, script_path_str.c_str()); - scoped_ptr c_argv = StringVectorToArgArray(args); node::Environment* env = node::CreateEnvironment( context->GetIsolate(), uv_default_loop(), context, - args.size(), c_argv.get(), 0, nullptr); + args.size(), &args[0], 0, nullptr); mate::Dictionary process(context->GetIsolate(), env->process_object()); process.Set("type", process_type);