Commit cfc7494a authored by Marius Wachtler's avatar Marius Wachtler

add the asserts back into stringpool

parent 2df05571
...@@ -42,6 +42,8 @@ private: ...@@ -42,6 +42,8 @@ private:
// Only for testing purposes: // Only for testing purposes:
InternedStringPool* pool; InternedStringPool* pool;
InternedString(const std::string* str, InternedStringPool* pool) : _str(str), pool(pool) {} InternedString(const std::string* str, InternedStringPool* pool) : _str(str), pool(pool) {}
static InternedStringPool* invalidPool() { return reinterpret_cast<InternedStringPool*>(-1); }
#else #else
InternedString(const std::string* str) : _str(str) {} InternedString(const std::string* str) : _str(str) {}
#endif #endif
...@@ -65,8 +67,9 @@ public: ...@@ -65,8 +67,9 @@ public:
} }
bool operator==(InternedString rhs) const { bool operator==(InternedString rhs) const {
assert(this->_str); assert(this->_str || this->pool == invalidPool());
assert(this->pool == rhs.pool); assert(rhs._str || rhs.pool == invalidPool());
assert(this->pool == rhs.pool || this->pool == invalidPool() || rhs.pool == invalidPool());
return this->_str == rhs._str; return this->_str == rhs._str;
} }
...@@ -134,17 +137,22 @@ template <> struct less<pyston::InternedString> { ...@@ -134,17 +137,22 @@ template <> struct less<pyston::InternedString> {
namespace llvm { namespace llvm {
template <> struct DenseMapInfo<pyston::InternedString> { template <> struct DenseMapInfo<pyston::InternedString> {
static inline pyston::InternedString getEmptyKey() { return pyston::InternedString(); } static inline pyston::InternedString getEmptyKey() {
#ifndef NDEBUG
return pyston::InternedString(nullptr, pyston::InternedString::invalidPool());
#else
return pyston::InternedString(nullptr);
#endif
}
static inline pyston::InternedString getTombstoneKey() { static inline pyston::InternedString getTombstoneKey() {
pyston::InternedString str; #ifndef NDEBUG
str._str = (const std::string*)-1; return pyston::InternedString((const std::string*)-1, pyston::InternedString::invalidPool());
return str; #else
return pyston::InternedString((const std::string*)-1);
#endif
} }
static unsigned getHashValue(const pyston::InternedString& val) { return std::hash<pyston::InternedString>()(val); } static unsigned getHashValue(const pyston::InternedString& val) { return std::hash<pyston::InternedString>()(val); }
static bool isEqual(const pyston::InternedString& lhs, const pyston::InternedString& rhs) { static bool isEqual(const pyston::InternedString& lhs, const pyston::InternedString& rhs) { return lhs == rhs; }
// Have to reimplement InternedString comparison otherwise asserts would trigger because of the empty keys.
return lhs._str == rhs._str;
}
}; };
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment