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

Unified Diff: base/command_line.h

Issue 1046073002: Add read-only mode to CommandLine that optimizes HasSwitch(const char*). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@whitelisted
Patch Set: Fix tests. Created 5 years, 9 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') | no next file with comments »
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..cf298a0e163cebd926403012dc057912e21cff87 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -156,6 +156,9 @@ class BASE_EXPORT CommandLine {
// Get a copy of all switches, along with their values.
const SwitchMap& GetSwitches() const { return switches_; }
+ const std::vector<std::string>& GetSwitchVector() const {
+ return switch_vector_;
+ }
// Append a switch [with optional value] to the command line.
// Note: Switches will precede arguments regardless of appending order.
@@ -198,6 +201,9 @@ class BASE_EXPORT CommandLine {
void ParseFromString(const base::string16& command_line);
#endif
+ // Optimizes lookups into this CommandLine, but it can no longer be modified.
+ void MakeReadOnly();
+
private:
// Disallow default constructor; a program name must be explicitly specified.
CommandLine();
@@ -214,6 +220,12 @@ class BASE_EXPORT CommandLine {
// also quotes parts with '%' in them.
StringType GetArgumentsStringInternal(bool quote_placeholders) const;
+ // Search for the switch in |switch_vector_|.
+ bool HasSwitchVector(const char string_constant[]) const;
+
+ // Search for the switch assuming the input is lowercase.
+ bool HasSwitchLowerCase(const char string_constant[]) const;
+
// The singleton CommandLine representing the current process's command line.
static CommandLine* current_process_commandline_;
@@ -225,6 +237,14 @@ class BASE_EXPORT CommandLine {
// The index after the program and switches, any arguments start here.
size_t begin_args_;
+
+ // A vector of switches. This allows looking up a const char* switch without
+ // allocating a string. It is initialized when this CommandLine is made
+ // read-only.
+ std::vector<std::string> switch_vector_;
+
+ // This is un-set when this CommandLine is made read-only.
+ bool writeable_;
};
} // namespace base
« no previous file with comments | « no previous file | base/command_line.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698