summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortapted <tapted@chromium.org>2015-03-29 20:57:10 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-30 03:57:42 +0000
commit009a1dc860942184fc6abdb4bedf854b15da7d91 (patch)
tree16612c10f058edf08e57d6aa2da5cf510f99caa9 /base
parent6983a3f9c5b228716e6b6ee1c477cfa1a42472a4 (diff)
downloadchromium_src-009a1dc860942184fc6abdb4bedf854b15da7d91.zip
chromium_src-009a1dc860942184fc6abdb4bedf854b15da7d91.tar.gz
chromium_src-009a1dc860942184fc6abdb4bedf854b15da7d91.tar.bz2
Provide CommandLine::HasSwitch(const char*) to save 76kB in sizes perf
Currently every callsite to CommandLine::HasSwitch() has to generate code to allocate a string on the stack, malloc(), copy characters from the switch constant, and then free things when it goes out of scope. Testing on a Mac release build, this results in about 76kB of generated object code. (about 40 bytes for each of the ~1928 calls in the non-test codebase). Adding a char[] overload allows this codegen to happen only once. And there's no lost inlining benefit since the new overload can inline its call instead. BUG=468184 Review URL: https://codereview.chromium.org/1007283012 Cr-Commit-Position: refs/heads/master@{#322737}
Diffstat (limited to 'base')
-rw-r--r--base/command_line.cc4
-rw-r--r--base/command_line.h3
2 files changed, 7 insertions, 0 deletions
diff --git a/base/command_line.cc b/base/command_line.cc
index d28a4b4..3e143cc 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -266,6 +266,10 @@ bool CommandLine::HasSwitch(const std::string& switch_string) const {
return switches_.find(LowerASCIIOnWindows(switch_string)) != switches_.end();
}
+bool CommandLine::HasSwitch(const char string_constant[]) const {
+ return HasSwitch(std::string(string_constant));
+}
+
std::string CommandLine::GetSwitchValueASCII(
const std::string& switch_string) const {
StringType value = GetSwitchValueNative(switch_string);
diff --git a/base/command_line.h b/base/command_line.h
index 85d924a..19df40c 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -143,7 +143,10 @@ class BASE_EXPORT CommandLine {
// Returns true if this command line contains the given switch.
// (Switch names are case-insensitive).
+ // The second override provides an optimized version to avoid inlining the
+ // codegen for the string allocation.
bool HasSwitch(const std::string& 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.