Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceStringPool.h - String pooling -------------*- C++ -*-===// | 1 //===- subzero/src/IceStringPool.h - String pooling -------------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 return toString(); | 105 return toString(); |
| 106 return ""; | 106 return ""; |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool operator==(const StringID &Other) const { return ID == Other.ID; } | 109 bool operator==(const StringID &Other) const { return ID == Other.ID; } |
| 110 bool operator!=(const StringID &Other) const { return !(*this == Other); } | 110 bool operator!=(const StringID &Other) const { return !(*this == Other); } |
| 111 bool operator<(const StringID &Other) const { | 111 bool operator<(const StringID &Other) const { |
| 112 const bool ThisHasString = hasStdString(); | 112 const bool ThisHasString = hasStdString(); |
| 113 const bool OtherHasString = Other.hasStdString(); | 113 const bool OtherHasString = Other.hasStdString(); |
| 114 // Do a normal string comparison if both have strings. | 114 // Do a normal string comparison if both have strings. |
| 115 if (ThisHasString && OtherHasString) | 115 if (ThisHasString && OtherHasString) |
|
Jim Stichnoth
2016/04/07 12:20:50
Here we test for both being true.
| |
| 116 return this->toString() < Other.toString(); | 116 return this->toString() < Other.toString(); |
| 117 // Use the ID as a tiebreaker if neither has a string. | 117 // Use the ID as a tiebreaker if neither has a string. |
| 118 if (!ThisHasString && !OtherHasString) | 118 if (!ThisHasString && !OtherHasString) |
|
Jim Stichnoth
2016/04/07 12:20:50
Here we test for both being false.
| |
| 119 return ID < Other.ID; | 119 return ID < Other.ID; |
| 120 // If exactly one has a string, then that one comes first. | 120 // If exactly one has a string, then that one comes first. |
| 121 assert(!OtherHasString); | 121 assert(ThisHasString != OtherHasString); |
|
Jim Stichnoth
2016/04/07 12:20:50
This is just meant to validate that one is true an
| |
| 122 return ThisHasString; | 122 return ThisHasString; |
| 123 } | 123 } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 static constexpr IDType InvalidID = 0; | 126 static constexpr IDType InvalidID = 0; |
| 127 IDType ID = InvalidID; | 127 IDType ID = InvalidID; |
| 128 | 128 |
| 129 explicit StringID(const typename Traits::OwnerType *Owner) | 129 explicit StringID(const typename Traits::OwnerType *Owner) |
| 130 : ID(Traits::getStrings(Owner)->getNewID()) {} | 130 : ID(Traits::getStrings(Owner)->getNewID()) {} |
| 131 StringID(const typename Traits::OwnerType *Owner, const std::string &Value) | 131 StringID(const typename Traits::OwnerType *Owner, const std::string &Value) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 template <typename T> struct hash<Ice::StringID<T>> { | 165 template <typename T> struct hash<Ice::StringID<T>> { |
| 166 size_t operator()(const Ice::StringID<T> &Key) const { | 166 size_t operator()(const Ice::StringID<T> &Key) const { |
| 167 if (Key.hasStdString()) | 167 if (Key.hasStdString()) |
| 168 return hash<std::string>()(Key.toString()); | 168 return hash<std::string>()(Key.toString()); |
| 169 return hash<Ice::StringPool::IDType>()(Key.getID()); | 169 return hash<Ice::StringPool::IDType>()(Key.getID()); |
| 170 } | 170 } |
| 171 }; | 171 }; |
| 172 } // end of namespace std | 172 } // end of namespace std |
| 173 | 173 |
| 174 #endif // SUBZERO_SRC_ICESTRINGPOOL_H | 174 #endif // SUBZERO_SRC_ICESTRINGPOOL_H |
| OLD | NEW |