summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjackhou <jackhou@chromium.org>2015-04-21 19:21:44 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-22 02:22:56 +0000
commitb20cbb495422e5f76f3064d73d3bb9c51113c45d (patch)
tree058aeb41cee40ff991570306ec42fff269dc6ec0 /base
parent4d03fdf9c5496f8bc323dcea744f2542ddde4ab6 (diff)
downloadchromium_src-b20cbb495422e5f76f3064d73d3bb9c51113c45d.zip
chromium_src-b20cbb495422e5f76f3064d73d3bb9c51113c45d.tar.gz
chromium_src-b20cbb495422e5f76f3064d73d3bb9c51113c45d.tar.bz2
Enforce lowercase switches when calling CommandLine::HasSwitch.
At the moment, all compile-time switches are lowercase. By enforcing this, we can skip converting it to lowercase on Windows, which saves one string allocation per call. On a profile with 2 extensions, HasSwitch is called ~12k times during startup. In an ideal situation (no paging/cache pressure), the string allocation under Windows takes ~137ns on an Xeon E5-2690 @ 2.9Ghz. So this should shave off at least 1.6ms off a typical startup with this hardware. For context, Startup.BrowserMessageLoopStartTimeFromMainEntry is typically 280-300ms on the same hardware, so we should get a ~0.5% improvement. BUG=472383 Committed: https://crrev.com/f58961749a980032241fe6c3fc829ac2e6652030 Cr-Commit-Position: refs/heads/master@{#325576} Review URL: https://codereview.chromium.org/1046363002 Cr-Commit-Position: refs/heads/master@{#326219}
Diffstat (limited to 'base')
-rw-r--r--base/command_line.cc3
-rw-r--r--base/command_line.h2
-rw-r--r--base/command_line_unittest.cc10
3 files changed, 8 insertions, 7 deletions
diff --git a/base/command_line.cc b/base/command_line.cc
index 3e143cc..61ff5c1 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -263,7 +263,8 @@ void CommandLine::SetProgram(const FilePath& program) {
}
bool CommandLine::HasSwitch(const std::string& switch_string) const {
- return switches_.find(LowerASCIIOnWindows(switch_string)) != switches_.end();
+ DCHECK_EQ(StringToLowerASCII(switch_string), switch_string);
+ return switches_.find(switch_string) != switches_.end();
}
bool CommandLine::HasSwitch(const char string_constant[]) const {
diff --git a/base/command_line.h b/base/command_line.h
index 19df40c..439921e 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -142,7 +142,7 @@ 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.
// The second override provides an optimized version to avoid inlining the
// codegen for the string allocation.
bool HasSwitch(const std::string& switch_string) const;
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index e395c856..db1a0b2 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -60,12 +60,13 @@ TEST(CommandLineTest, CommandLineConstructor) {
cl.GetProgram().value());
EXPECT_TRUE(cl.HasSwitch("foo"));
- EXPECT_TRUE(cl.HasSwitch("bAr"));
- EXPECT_TRUE(cl.HasSwitch("baz"));
- EXPECT_TRUE(cl.HasSwitch("spaetzle"));
#if defined(OS_WIN)
- EXPECT_TRUE(cl.HasSwitch("SPAETZLE"));
+ EXPECT_TRUE(cl.HasSwitch("bar"));
+#else
+ EXPECT_FALSE(cl.HasSwitch("bar"));
#endif
+ EXPECT_TRUE(cl.HasSwitch("baz"));
+ EXPECT_TRUE(cl.HasSwitch("spaetzle"));
EXPECT_TRUE(cl.HasSwitch("other-switches"));
EXPECT_TRUE(cl.HasSwitch("input-translation"));
@@ -128,7 +129,6 @@ TEST(CommandLineTest, CommandLineFromString) {
EXPECT_TRUE(cl.HasSwitch("bar"));
EXPECT_TRUE(cl.HasSwitch("baz"));
EXPECT_TRUE(cl.HasSwitch("spaetzle"));
- EXPECT_TRUE(cl.HasSwitch("SPAETZLE"));
EXPECT_TRUE(cl.HasSwitch("other-switches"));
EXPECT_TRUE(cl.HasSwitch("input-translation"));
EXPECT_TRUE(cl.HasSwitch("quotes"));