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

Unified Diff: base/command_line.h

Issue 1063933002: Take a StringPiece when looking up CommandLine switches. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cmd
Patch Set: Override copy and assign. Created 5 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 | « no previous file | base/command_line.cc » ('j') | base/command_line.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/command_line.h
diff --git a/base/command_line.h b/base/command_line.h
index 19df40c4c478bfa9befe59ad9eefc63f5b33c55f..e6f999536e143721d5c31a92ebf487bf7133c825 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -22,6 +22,7 @@
#include "base/base_export.h"
#include "base/strings/string16.h"
+#include "base/strings/string_piece.h"
#include "build/build_config.h"
namespace base {
@@ -52,6 +53,10 @@ class BASE_EXPORT CommandLine {
CommandLine(int argc, const CharType* const* argv);
explicit CommandLine(const StringVector& argv);
+ // Override copy and assign to ensure |switches_by_stringpiece_| is valid.
+ CommandLine(const CommandLine& other);
tapted 2015/04/15 00:07:53 it's tempting to make this explicit... I bet a lot
+ CommandLine& operator=(const CommandLine& other);
+
~CommandLine();
#if defined(OS_WIN)
@@ -142,19 +147,19 @@ class BASE_EXPORT CommandLine {
void SetProgram(const FilePath& program);
// Returns true if this command line contains the given switch.
- // (Switch names are case-insensitive).
+ // Switch names should only be lowercase.
tapted 2015/04/15 00:07:53 nit: should only -> must
jackhou1 2015/04/17 00:56:10 Done.
// The second override provides an optimized version to avoid inlining the
// codegen for the string allocation.
tapted 2015/04/15 00:07:53 This last sentence in the comment is no longer val
jackhou1 2015/04/17 00:56:10 Done.
- bool HasSwitch(const std::string& switch_string) const;
- bool HasSwitch(const char switch_constant[]) const;
+ bool HasSwitch(const base::StringPiece& switch_string) const;
// Returns the value associated with the given switch. If the switch has no
// value or isn't present, this method returns the empty string.
- std::string GetSwitchValueASCII(const std::string& switch_string) const;
- FilePath GetSwitchValuePath(const std::string& switch_string) const;
- StringType GetSwitchValueNative(const std::string& switch_string) const;
+ // Switch names should only be lowercase.
+ std::string GetSwitchValueASCII(const base::StringPiece& switch_string) const;
+ FilePath GetSwitchValuePath(const base::StringPiece& switch_string) const;
+ StringType GetSwitchValueNative(const base::StringPiece& switch_string) const;
- // Get a copy of all switches, along with their values.
+ // Get a reference to the internal switch map.
const SwitchMap& GetSwitches() const { return switches_; }
// Append a switch [with optional value] to the command line.
@@ -223,6 +228,10 @@ class BASE_EXPORT CommandLine {
// Parsed-out switch keys and values.
SwitchMap switches_;
+ // A mirror of |switches_| with only references to the actual strings.
+ // Used for allocation-free lookups.
tapted 2015/04/15 00:07:53 nit: mention mapped_type points to an object in |s
jackhou1 2015/04/17 00:56:10 Done.
+ std::map<base::StringPiece, const StringType*> switches_by_stringpiece_;
tapted 2015/04/15 00:07:53 It might be less confusing to just store a value f
jackhou1 2015/04/17 00:56:10 I'm think the memory/performance impact would be n
+
// The index after the program and switches, any arguments start here.
size_t begin_args_;
};
« no previous file with comments | « no previous file | base/command_line.cc » ('j') | base/command_line.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698