| 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 |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 BASE_EXPORT std::ostream& operator<<(std::ostream& o, | 432 BASE_EXPORT std::ostream& operator<<(std::ostream& o, |
| 433 const StringPiece& piece); | 433 const StringPiece& piece); |
| 434 | 434 |
| 435 } // namespace base | 435 } // namespace base |
| 436 | 436 |
| 437 // Hashing --------------------------------------------------------------------- | 437 // Hashing --------------------------------------------------------------------- |
| 438 | 438 |
| 439 // We provide appropriate hash functions so StringPiece and StringPiece16 can | 439 // We provide appropriate hash functions so StringPiece and StringPiece16 can |
| 440 // be used as keys in hash sets and maps. | 440 // be used as keys in hash sets and maps. |
| 441 | 441 |
| 442 // This hash function is copied from base/containers/hash_tables.h. We don't | 442 // This hash function is copied from base/strings/string16.h. We don't use the |
| 443 // use the ones already defined for string and string16 directly because it | 443 // ones already defined for string and string16 directly because it would |
| 444 // would require the string constructors to be called, which we don't want. | 444 // require the string constructors to be called, which we don't want. |
| 445 #define HASH_STRING_PIECE(StringPieceType, string_piece) \ | 445 #define HASH_STRING_PIECE(StringPieceType, string_piece) \ |
| 446 std::size_t result = 0; \ | 446 std::size_t result = 0; \ |
| 447 for (StringPieceType::const_iterator i = string_piece.begin(); \ | 447 for (StringPieceType::const_iterator i = string_piece.begin(); \ |
| 448 i != string_piece.end(); ++i) \ | 448 i != string_piece.end(); ++i) \ |
| 449 result = (result * 131) + *i; \ | 449 result = (result * 131) + *i; \ |
| 450 return result; \ | 450 return result; \ |
| 451 | 451 |
| 452 namespace BASE_HASH_NAMESPACE { | 452 namespace BASE_HASH_NAMESPACE { |
| 453 | 453 |
| 454 template<> | 454 template<> |
| 455 struct hash<base::StringPiece> { | 455 struct hash<base::StringPiece> { |
| 456 std::size_t operator()(const base::StringPiece& sp) const { | 456 std::size_t operator()(const base::StringPiece& sp) const { |
| 457 HASH_STRING_PIECE(base::StringPiece, sp); | 457 HASH_STRING_PIECE(base::StringPiece, sp); |
| 458 } | 458 } |
| 459 }; | 459 }; |
| 460 template<> | 460 template<> |
| 461 struct hash<base::StringPiece16> { | 461 struct hash<base::StringPiece16> { |
| 462 std::size_t operator()(const base::StringPiece16& sp16) const { | 462 std::size_t operator()(const base::StringPiece16& sp16) const { |
| 463 HASH_STRING_PIECE(base::StringPiece16, sp16); | 463 HASH_STRING_PIECE(base::StringPiece16, sp16); |
| 464 } | 464 } |
| 465 }; | 465 }; |
| 466 | 466 |
| 467 } // namespace BASE_HASH_NAMESPACE | 467 } // namespace BASE_HASH_NAMESPACE |
| 468 | 468 |
| 469 #endif // BASE_STRINGS_STRING_PIECE_H_ | 469 #endif // BASE_STRINGS_STRING_PIECE_H_ |
| OLD | NEW |