added random salt to NamePool hash

This commit is contained in:
Günter Obiltschnig 2017-08-10 12:18:18 +02:00
parent a176c8d1f2
commit f37520b30b
2 changed files with 8 additions and 1 deletions

View File

@ -74,6 +74,7 @@ private:
NamePoolItem* _pItems;
unsigned long _size;
unsigned long _salt;
int _rc;
};

View File

@ -16,6 +16,7 @@
#include "Poco/XML/NamePool.h"
#include "Poco/Exception.h"
#include "Poco/Random.h"
namespace Poco {
@ -62,11 +63,16 @@ private:
NamePool::NamePool(unsigned long size):
_size(size),
_salt(0),
_rc(1)
{
poco_assert (size > 1);
_pItems = new NamePoolItem[size];
Poco::Random rnd;
rnd.seed();
_salt = rnd.next();
}
@ -92,7 +98,7 @@ void NamePool::release()
const Name& NamePool::insert(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName)
{
unsigned long i = 0;
unsigned long n = hash(qname, namespaceURI, localName) % _size;
unsigned long n = (hash(qname, namespaceURI, localName) ^ _salt) % _size;
while (!_pItems[n].set(qname, namespaceURI, localName) && i++ < _size)
n = (n + 1) % _size;