Using StringPiece breaks Windows build.
| 59 | |
| 60 | // Using StringPiece breaks Windows build. |
| 61 | struct StringData { |
| 62 | struct Hasher { |
| 63 | size_t operator()(const StringData& sdata) const { |
| 64 | // For dependency reasons, we cannot use hash.h here. Use DBJHash instead. |
| 65 | size_t hash = 5381; |
| 66 | const char* data = sdata.data; |
| 67 | for (const char* top = data + sdata.size; data < top; ++data) { |
| 68 | hash = ((hash << 5) + hash) + (*data); |
| 69 | } |
| 70 | return hash; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | StringData() = default; |
| 75 | StringData(const char* data, size_t size) : data(data), size(size) {} |
| 76 | |
| 77 | bool operator==(const StringData& rhs) const { |
| 78 | return size == rhs.size && memcmp(data, rhs.data, size) == 0; |
| 79 | } |
| 80 | friend std::ostream& operator<<(std::ostream& out, const StringData& s); |
| 81 | |
| 82 | const char* data = nullptr; |
| 83 | size_t size = 0; |
| 84 | }; |
| 85 | |
| 86 | std::ostream& operator<<(std::ostream& out, const StringData& s) { |
| 87 | out << std::string(s.data, s.size); |
no outgoing calls
no test coverage detected