Chromium Code Reviews

Side by Side Diff: src/IceStringPool.h

Issue 1866993002: Subzero: Fix an incorrect StringPool assert. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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...)
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...)
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine