Skip to content

Commit 0d7e2a3

Browse files
committed
Change signature hash function
1 parent 2f05873 commit 0d7e2a3

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

src/NativeScript/Calling/FFICache.h

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,27 @@
1313
#include <vector>
1414

1515
namespace NativeScript {
16-
17-
struct SignatureHash {
18-
19-
std::size_t operator()(std::vector<const ffi_type*> signature) const {
20-
std::size_t seed = 0;
21-
22-
23-
for(size_t i = 0; i < signature.size(); i++) {
24-
seed <<= 4;
25-
seed |= signature[i]->type;
26-
}
27-
return seed;
16+
17+
struct SignatureHash {
18+
19+
std::size_t operator()(std::vector<const ffi_type*> signature) const {
20+
std::size_t seed = 2166136261;
21+
22+
for (size_t i = 0; i < signature.size(); i++) {
23+
seed = (seed ^ reinterpret_cast<size_t>(signature[i])) * 16777619U;
2824
}
29-
30-
};
31-
32-
class FFICache {
33-
34-
public:
35-
36-
std::unordered_map<std::vector<const ffi_type*>, std::shared_ptr<ffi_cif>, SignatureHash> cifCache;
37-
38-
static FFICache *global();
39-
40-
};
41-
42-
}
25+
return seed;
26+
}
27+
};
28+
29+
class FFICache {
30+
31+
public:
32+
std::unordered_map<std::vector<const ffi_type*>, std::shared_ptr<ffi_cif>, SignatureHash> cifCache;
33+
34+
static FFICache* global();
35+
};
4336

37+
} // namespace NativeScript
4438

4539
#endif /* FFICache_h */

0 commit comments

Comments
 (0)