| 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 // use the ones already defined for string and string16 directly because it | 432 // use the ones already defined for string and string16 directly because it |
| 433 // would require the string constructors to be called, which we don't want. | 433 // would require the string constructors to be called, which we don't want. |
| 434 #define HASH_STRING_PIECE(StringPieceType, string_piece) \ | 434 #define HASH_STRING_PIECE(StringPieceType, string_piece) \ |
| 435 std::size_t result = 0; \ | 435 std::size_t result = 0; \ |
| 436 for (StringPieceType::const_iterator i = string_piece.begin(); \ | 436 for (StringPieceType::const_iterator i = string_piece.begin(); \ |
| 437 i != string_piece.end(); ++i) \ | 437 i != string_piece.end(); ++i) \ |
| 438 result = (result * 131) + *i; \ | 438 result = (result * 131) + *i; \ |
| 439 return result; \ | 439 return result; \ |
| 440 | 440 |
| 441 namespace BASE_HASH_NAMESPACE { | 441 namespace BASE_HASH_NAMESPACE { |
| 442 #if defined(COMPILER_GCC) | |
| 443 | 442 |
| 444 template<> | 443 template<> |
| 445 struct hash<base::StringPiece> { | 444 struct hash<base::StringPiece> { |
| 446 std::size_t operator()(const base::StringPiece& sp) const { | 445 std::size_t operator()(const base::StringPiece& sp) const { |
| 447 HASH_STRING_PIECE(base::StringPiece, sp); | 446 HASH_STRING_PIECE(base::StringPiece, sp); |
| 448 } | 447 } |
| 449 }; | 448 }; |
| 450 template<> | 449 template<> |
| 451 struct hash<base::StringPiece16> { | 450 struct hash<base::StringPiece16> { |
| 452 std::size_t operator()(const base::StringPiece16& sp16) const { | 451 std::size_t operator()(const base::StringPiece16& sp16) const { |
| 453 HASH_STRING_PIECE(base::StringPiece16, sp16); | 452 HASH_STRING_PIECE(base::StringPiece16, sp16); |
| 454 } | 453 } |
| 455 }; | 454 }; |
| 456 | 455 |
| 457 #elif defined(COMPILER_MSVC) | |
| 458 | |
| 459 inline size_t hash_value(const base::StringPiece& sp) { | |
| 460 HASH_STRING_PIECE(base::StringPiece, sp); | |
| 461 } | |
| 462 inline size_t hash_value(const base::StringPiece16& sp16) { | |
| 463 HASH_STRING_PIECE(base::StringPiece16, sp16); | |
| 464 } | |
| 465 | |
| 466 #endif // COMPILER | |
| 467 | |
| 468 } // namespace BASE_HASH_NAMESPACE | 456 } // namespace BASE_HASH_NAMESPACE |
| 469 | 457 |
| 470 #endif // BASE_STRINGS_STRING_PIECE_H_ | 458 #endif // BASE_STRINGS_STRING_PIECE_H_ |
| OLD | NEW |