I propose to slightly change the default implementation of __stl_hash_string in _hash_fun.h to improve speed. The inner loop is currently:
__h = 5*__h + *__s;
This can be changed to
__h = (__h << 2) + h + *__s;
Since __h is unsigned, this will not result in any difference in the value computed.
On my x86 machine this results in a 50% speed improvement for this hash function. Since string hashing is relatively common and this change is trivial, I don't see why it couldn't be done.
Log in to post a comment.