| Index: base/command_line.h
|
| diff --git a/base/command_line.h b/base/command_line.h
|
| index 19df40c4c478bfa9befe59ad9eefc63f5b33c55f..48b54ea80a6104c1834eacb607c25a0ba580ae52 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);
|
| + CommandLine& operator=(const CommandLine& other);
|
| +
|
| ~CommandLine();
|
|
|
| #if defined(OS_WIN)
|
| @@ -142,19 +147,20 @@ 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 must be lowercase.
|
| // The second override provides an optimized version to avoid inlining the
|
| - // codegen for the string allocation.
|
| - bool HasSwitch(const std::string& switch_string) const;
|
| + // codegen to find the length of the constant and construct a StringPiece.
|
| + bool HasSwitch(const base::StringPiece& switch_string) const;
|
| bool HasSwitch(const char switch_constant[]) 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 must 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 +229,12 @@ class BASE_EXPORT CommandLine {
|
| // Parsed-out switch keys and values.
|
| SwitchMap switches_;
|
|
|
| + // A mirror of |switches_| with only references to the actual strings.
|
| + // The StringPiece internally holds a pointer to a key in |switches_| while
|
| + // the mapped_type points to a value in |switches_|.
|
| + // Used for allocation-free lookups.
|
| + std::map<base::StringPiece, const StringType*> switches_by_stringpiece_;
|
| +
|
| // The index after the program and switches, any arguments start here.
|
| size_t begin_args_;
|
| };
|
|
|