OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // Copied from strings/stringpiece.h with modifications | 4 // Copied from strings/stringpiece.h with modifications |
5 // | 5 // |
6 // A string-like object that points to a sized piece of memory. | 6 // A string-like object that points to a sized piece of memory. |
7 // | 7 // |
8 // You can use StringPiece as a function or method parameter. A StringPiece | 8 // You can use StringPiece as a function or method parameter. A StringPiece |
9 // parameter can receive a double-quoted string literal argument, a "const | 9 // parameter can receive a double-quoted string literal argument, a "const |
10 // char*" argument, a string argument, or a StringPiece argument with no data | 10 // char*" argument, a string argument, or a StringPiece argument with no data |
11 // copying. Systematic use of StringPiece for arguments reduces data | 11 // copying. Systematic use of StringPiece for arguments reduces data |
12 // copies and strlen() calls. | 12 // copies and strlen() calls. |
13 // | 13 // |
14 // Prefer passing StringPieces by value: | 14 // Prefer passing StringPieces by value: |
15 // void MyFunction(StringPiece arg); | 15 // void MyFunction(StringPiece arg); |
16 // If circumstances require, you may also pass by const reference: | 16 // If circumstances require, you may also pass by const reference: |
17 // void MyFunction(const StringPiece& arg); // not preferred | 17 // void MyFunction(const StringPiece& arg); // not preferred |
18 // Both of these have the same lifetime semantics. Passing by value | 18 // Both of these have the same lifetime semantics. Passing by value |
19 // generates slightly smaller code. For more discussion, Googlers can see | 19 // generates slightly smaller code. For more discussion, Googlers can see |
20 // the thread go/stringpiecebyvalue on c-users. | 20 // the thread go/stringpiecebyvalue on c-users. |
21 // | |
22 // StringPiece16 is similar to StringPiece but for base::string16 instead of | |
23 // std::string. We do not define as large of a subset of the STL functions | |
24 // from basic_string as in StringPiece, but this can be changed if these | |
25 // functions (find, find_first_of, etc.) are found to be useful in this context. | |
26 // | |
27 | 21 |
28 #ifndef BASE_STRINGS_STRING_PIECE_H_ | 22 #ifndef BASE_STRINGS_STRING_PIECE_H_ |
29 #define BASE_STRINGS_STRING_PIECE_H_ | 23 #define BASE_STRINGS_STRING_PIECE_H_ |
30 | 24 |
31 #include <stddef.h> | 25 #include <stddef.h> |
32 | 26 |
33 #include <iosfwd> | 27 #include <iosfwd> |
34 #include <string> | 28 #include <string> |
35 | 29 |
36 #include "base/base_export.h" | 30 #include "base/base_export.h" |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 template<> | 443 template<> |
450 struct hash<base::StringPiece16> { | 444 struct hash<base::StringPiece16> { |
451 std::size_t operator()(const base::StringPiece16& sp16) const { | 445 std::size_t operator()(const base::StringPiece16& sp16) const { |
452 HASH_STRING_PIECE(base::StringPiece16, sp16); | 446 HASH_STRING_PIECE(base::StringPiece16, sp16); |
453 } | 447 } |
454 }; | 448 }; |
455 | 449 |
456 } // namespace BASE_HASH_NAMESPACE | 450 } // namespace BASE_HASH_NAMESPACE |
457 | 451 |
458 #endif // BASE_STRINGS_STRING_PIECE_H_ | 452 #endif // BASE_STRINGS_STRING_PIECE_H_ |
OLD | NEW |