summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-13 15:45:34 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-13 15:45:34 +0000
commit1fa39f057d59aeee2b9f36cf3b152528a1197ae1 (patch)
treeb7aa03c2bb6d8e79f636252eda7fab02b059cd14 /base
parent691a97e5081651a1df05eb9a59b6ce111e949350 (diff)
downloadchromium_src-1fa39f057d59aeee2b9f36cf3b152528a1197ae1.zip
chromium_src-1fa39f057d59aeee2b9f36cf3b152528a1197ae1.tar.gz
chromium_src-1fa39f057d59aeee2b9f36cf3b152528a1197ae1.tar.bz2
micro optimize CommandLine.GetSwitchPrefixLength
avoid searching the entire length of each switch for the -- prefix, as we know it can only exist at the start. BUG=None TEST=None Review URL: http://codereview.chromium.org/7866036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100918 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/command_line.cc2
-rw-r--r--base/command_line_unittest.cc5
2 files changed, 5 insertions, 2 deletions
diff --git a/base/command_line.cc b/base/command_line.cc
index b028226..22977af 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -37,7 +37,7 @@ const CommandLine::CharType* const kSwitchPrefixes[] = {"--", "-"};
size_t GetSwitchPrefixLength(const CommandLine::StringType& string) {
for (size_t i = 0; i < arraysize(kSwitchPrefixes); ++i) {
CommandLine::StringType prefix(kSwitchPrefixes[i]);
- if (string.find(prefix) == 0)
+ if (string.compare(0, prefix.length(), prefix) == 0)
return prefix.length();
}
return 0;
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index 80874ac..656236e 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -34,6 +34,7 @@ TEST(CommandLineTest, CommandLineConstructor) {
FILE_PATH_LITERAL("-spaetzle=Crepe"),
FILE_PATH_LITERAL("-=loosevalue"),
FILE_PATH_LITERAL("FLAN"),
+ FILE_PATH_LITERAL("a"),
FILE_PATH_LITERAL("--input-translation=45--output-rotation"),
FILE_PATH_LITERAL("--"),
FILE_PATH_LITERAL("--"),
@@ -74,13 +75,15 @@ TEST(CommandLineTest, CommandLineConstructor) {
EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation"));
const CommandLine::StringVector& args = cl.GetArgs();
- ASSERT_EQ(6U, args.size());
+ ASSERT_EQ(7U, args.size());
std::vector<CommandLine::StringType>::const_iterator iter = args.begin();
EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter);
++iter;
EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter);
++iter;
+ EXPECT_EQ(FILE_PATH_LITERAL("a"), *iter);
+ ++iter;
EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter);
++iter;
EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter);