]> Savannah Git Hosting - gnulib.git/commitdiff
module: a faster hash computation
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 12 Jan 2018 20:09:16 +0000 (23:09 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Fri, 12 Jan 2018 20:09:16 +0000 (23:09 +0300)
pygnulib/module.py

index ad14e8c11f8a46f74e2062a3e57d1e62ff62a6e7..f3bfbc7dbd843bcbbc384b8cf59155dfd2253f2a 100644 (file)
@@ -6,8 +6,9 @@
 
 import ast as _ast
 import codecs as _codecs
-import hashlib as _hashlib
 import collections as _collections
+import hashlib as _hashlib
+import json as _json
 import os as _os
 import re as _re
 
@@ -78,10 +79,7 @@ class BaseModule:
 
 
     def __hash__(self):
-        result = hash(self.__name)
-        for key in sorted(self.keys()):
-            result ^= hash(tuple(self[key]))
-        return result
+        return hash(self.__name) ^ _json.dumps(self.__table, sort_keys=True)
 
 
     def __getitem__(self, key):