Commit dc25448a authored by Boxiang Sun's avatar Boxiang Sun

some adjustment to use new string hash function

parent f76fb2fe
...@@ -39,6 +39,7 @@ BoxedDict* sys_modules_dict; ...@@ -39,6 +39,7 @@ BoxedDict* sys_modules_dict;
extern "C" { extern "C" {
// supposed to be exposed through sys.flags // supposed to be exposed through sys.flags
int Py_BytesWarningFlag = 0; int Py_BytesWarningFlag = 0;
int Py_HashRandomizationFlag = 0;
} }
Box* sysExcInfo() { Box* sysExcInfo() {
......
...@@ -130,9 +130,8 @@ size_t PyHasher::operator()(Box* b) const { ...@@ -130,9 +130,8 @@ size_t PyHasher::operator()(Box* b) const {
ScopedStatTimer _st(pyhasher_timer_counter, 10); ScopedStatTimer _st(pyhasher_timer_counter, 10);
#endif #endif
if (b->cls == str_cls) { if (b->cls == str_cls) {
StringHash<char> H;
auto s = static_cast<BoxedString*>(b); auto s = static_cast<BoxedString*>(b);
return H(s->data(), s->size()); return strHashUnboxed(s);
} }
return hashUnboxed(b); return hashUnboxed(b);
......
...@@ -430,36 +430,7 @@ private: ...@@ -430,36 +430,7 @@ private:
friend void setupRuntime(); friend void setupRuntime();
}; };
template <typename T> struct StringHash { extern "C" size_t strHashUnboxed(BoxedString* self);
size_t operator()(const T* str) {
size_t hash = 5381;
T c;
while ((c = *str++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}
size_t operator()(const T* str, int len) {
size_t hash = 5381;
T c;
while (--len >= 0) {
c = *str++;
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
}
return hash;
}
};
template <> struct StringHash<std::string> {
size_t operator()(const std::string& str) {
StringHash<char> H;
return H(&str[0], str.size());
}
};
class BoxedInstanceMethod : public Box { class BoxedInstanceMethod : public Box {
public: public:
......
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