diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-29 13:11:36 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-29 13:11:36 +0000 |
commit | 2423881b28e6944b3f61fe70af6222ef0a75d59e (patch) | |
tree | 312b39ed379bd480db83b143fba419205698aed9 /base | |
parent | b7b24f6a1512fdfb3b1f292242e62490b5c6b9fd (diff) | |
download | chromium_src-2423881b28e6944b3f61fe70af6222ef0a75d59e.zip chromium_src-2423881b28e6944b3f61fe70af6222ef0a75d59e.tar.gz chromium_src-2423881b28e6944b3f61fe70af6222ef0a75d59e.tar.bz2 |
Move a few functions commonly called with char* to StringPiece.
In some cases this will avoid the implicit char* -> std::string conversion,
object creation, and string copying. One of the biggest benefit is on Windows,
where we can save some conversions in FilePath::AppendASCII.
Review URL: http://codereview.chromium.org/113996
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17182 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/file_path.cc | 4 | ||||
-rw-r--r-- | base/file_path.h | 3 | ||||
-rw-r--r-- | base/string_util.cc | 6 | ||||
-rw-r--r-- | base/string_util.h | 6 |
4 files changed, 10 insertions, 9 deletions
diff --git a/base/file_path.cc b/base/file_path.cc index b1bf687..a00659e 100644 --- a/base/file_path.cc +++ b/base/file_path.cc @@ -252,12 +252,12 @@ FilePath FilePath::Append(const FilePath& component) const { return Append(component.value()); } -FilePath FilePath::AppendASCII(const std::string& component) const { +FilePath FilePath::AppendASCII(const StringPiece& component) const { DCHECK(IsStringASCII(component)); #if defined(OS_WIN) return Append(ASCIIToWide(component)); #elif defined(OS_POSIX) - return Append(component); + return Append(component.as_string()); #endif } diff --git a/base/file_path.h b/base/file_path.h index d4f35d1..73de4a6 100644 --- a/base/file_path.h +++ b/base/file_path.h @@ -70,6 +70,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/hash_tables.h" +#include "base/string_piece.h" // For implicit conversions. // Windows-style drive letter support and pathname separator characters can be // enabled and disabled independently, to aid testing. These #defines are @@ -199,7 +200,7 @@ class FilePath { // On Linux, although it can use any 8-bit encoding for paths, we assume that // ASCII is a valid subset, regardless of the encoding, since many operating // system paths will always be ASCII. - FilePath AppendASCII(const std::string& component) const WARN_UNUSED_RESULT; + FilePath AppendASCII(const StringPiece& component) const WARN_UNUSED_RESULT; // Returns true if this FilePath contains an absolute path. On Windows, an // absolute path begins with either a drive letter specification followed by diff --git a/base/string_util.cc b/base/string_util.cc index c666960..1cdbd7b 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -466,7 +466,7 @@ std::string WideToASCII(const std::wstring& wide) { return std::string(wide.begin(), wide.end()); } -std::wstring ASCIIToWide(const std::string& ascii) { +std::wstring ASCIIToWide(const StringPiece& ascii) { DCHECK(IsStringASCII(ascii)); return std::wstring(ascii.begin(), ascii.end()); } @@ -476,7 +476,7 @@ std::string UTF16ToASCII(const string16& utf16) { return std::string(utf16.begin(), utf16.end()); } -string16 ASCIIToUTF16(const std::string& ascii) { +string16 ASCIIToUTF16(const StringPiece& ascii) { DCHECK(IsStringASCII(ascii)); return string16(ascii.begin(), ascii.end()); } @@ -523,7 +523,7 @@ bool IsStringASCII(const string16& str) { } #endif -bool IsStringASCII(const std::string& str) { +bool IsStringASCII(const StringPiece& str) { return DoIsStringASCII(str); } diff --git a/base/string_util.h b/base/string_util.h index f40cc8d..b082078 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -174,9 +174,9 @@ std::wstring CollapseWhitespace(const std::wstring& text, // These convert between ASCII (7-bit) and Wide/UTF16 strings. std::string WideToASCII(const std::wstring& wide); -std::wstring ASCIIToWide(const std::string& ascii); +std::wstring ASCIIToWide(const StringPiece& ascii); std::string UTF16ToASCII(const string16& utf16); -string16 ASCIIToUTF16(const std::string& ascii); +string16 ASCIIToUTF16(const StringPiece& ascii); // These convert between UTF-8, -16, and -32 strings. They are potentially slow, // so avoid unnecessary conversions. The low-level versions return a boolean @@ -252,7 +252,7 @@ bool IsString8Bit(const std::wstring& str); bool IsStringUTF8(const std::string& str); bool IsStringWideUTF8(const std::wstring& str); bool IsStringASCII(const std::wstring& str); -bool IsStringASCII(const std::string& str); +bool IsStringASCII(const StringPiece& str); bool IsStringASCII(const string16& str); // ASCII-specific tolower. The standard library's tolower is locale sensitive, |