mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-03 15:58:23 +02:00
added random salt to NamePool hash
This commit is contained in:
parent
a176c8d1f2
commit
f37520b30b
@ -74,6 +74,7 @@ private:
|
|||||||
|
|
||||||
NamePoolItem* _pItems;
|
NamePoolItem* _pItems;
|
||||||
unsigned long _size;
|
unsigned long _size;
|
||||||
|
unsigned long _salt;
|
||||||
int _rc;
|
int _rc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "Poco/XML/NamePool.h"
|
#include "Poco/XML/NamePool.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
#include "Poco/Random.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@ -62,11 +63,16 @@ private:
|
|||||||
|
|
||||||
NamePool::NamePool(unsigned long size):
|
NamePool::NamePool(unsigned long size):
|
||||||
_size(size),
|
_size(size),
|
||||||
|
_salt(0),
|
||||||
_rc(1)
|
_rc(1)
|
||||||
{
|
{
|
||||||
poco_assert (size > 1);
|
poco_assert (size > 1);
|
||||||
|
|
||||||
_pItems = new NamePoolItem[size];
|
_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)
|
const Name& NamePool::insert(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName)
|
||||||
{
|
{
|
||||||
unsigned long i = 0;
|
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)
|
while (!_pItems[n].set(qname, namespaceURI, localName) && i++ < _size)
|
||||||
n = (n + 1) % _size;
|
n = (n + 1) % _size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user