mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 10:52:56 +00:00
just generate some heat from QUuid::createUuid()
it is simply faster Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
37e0c5bb84
commit
487b736da1
1 changed files with 28 additions and 57 deletions
|
@ -827,74 +827,45 @@ QT_BEGIN_INCLUDE_NAMESPACE
|
|||
#include <stdlib.h> // for RAND_MAX
|
||||
QT_END_INCLUDE_NAMESPACE
|
||||
|
||||
#if !defined(QT_BOOTSTRAPPED) && defined(Q_OS_UNIX)
|
||||
Q_GLOBAL_STATIC(QThreadStorage<QFile *>, devUrandomStorage)
|
||||
#endif
|
||||
|
||||
QUuid QUuid::createUuid()
|
||||
{
|
||||
QUuid result;
|
||||
uint *data = &(result.data1);
|
||||
|
||||
#if defined(Q_OS_UNIX)
|
||||
QFile *devUrandom;
|
||||
# if !defined(QT_BOOTSTRAPPED)
|
||||
devUrandom = devUrandomStorage()->localData();
|
||||
if (!devUrandom) {
|
||||
devUrandom = new QFile(QLatin1String("/dev/urandom"));
|
||||
devUrandom->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
|
||||
devUrandomStorage()->setLocalData(devUrandom);
|
||||
static const int intbits = sizeof(int)*8;
|
||||
static int randbits = 0;
|
||||
if (!randbits) {
|
||||
int r = 0;
|
||||
int max = RAND_MAX;
|
||||
do { ++r; } while ((max=max>>1));
|
||||
randbits = r;
|
||||
}
|
||||
# else
|
||||
QFile file(QLatin1String("/dev/urandom"));
|
||||
devUrandom = &file;
|
||||
devUrandom->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
|
||||
# endif
|
||||
enum { AmountToRead = 4 * sizeof(uint) };
|
||||
if (devUrandom->isOpen()
|
||||
&& devUrandom->read((char *) data, AmountToRead) == AmountToRead) {
|
||||
// we got what we wanted, nothing more to do
|
||||
;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
static const int intbits = sizeof(int)*8;
|
||||
static int randbits = 0;
|
||||
if (!randbits) {
|
||||
int r = 0;
|
||||
int max = RAND_MAX;
|
||||
do { ++r; } while ((max=max>>1));
|
||||
randbits = r;
|
||||
}
|
||||
|
||||
// Seed the PRNG once per thread with a combination of current time, a
|
||||
// stack address and a serial counter (since thread stack addresses are
|
||||
// re-used).
|
||||
// Seed the PRNG once per thread with a combination of current time, a
|
||||
// stack address and a serial counter (since thread stack addresses are
|
||||
// re-used).
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
static QThreadStorage<int *> uuidseed;
|
||||
if (!uuidseed.hasLocalData())
|
||||
{
|
||||
int *pseed = new int;
|
||||
static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2);
|
||||
qsrand(*pseed = QDateTime::currentDateTime().toTime_t()
|
||||
+ quintptr(&pseed)
|
||||
+ serial.fetchAndAddRelaxed(1));
|
||||
uuidseed.setLocalData(pseed);
|
||||
}
|
||||
static QThreadStorage<int *> uuidseed;
|
||||
if (!uuidseed.hasLocalData()) {
|
||||
int *pseed = new int;
|
||||
static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2);
|
||||
qsrand(*pseed = QDateTime::currentDateTime().toTime_t()
|
||||
+ quintptr(&pseed)
|
||||
+ serial.fetchAndAddRelaxed(1));
|
||||
uuidseed.setLocalData(pseed);
|
||||
}
|
||||
#else
|
||||
static bool seeded = false;
|
||||
if (!seeded)
|
||||
qsrand(QDateTime::currentDateTime().toTime_t()
|
||||
+ quintptr(&seeded));
|
||||
static bool seeded = false;
|
||||
if (!seeded)
|
||||
qsrand(QDateTime::currentDateTime().toTime_t() + quintptr(&seeded));
|
||||
#endif
|
||||
|
||||
int chunks = 16 / sizeof(uint);
|
||||
while (chunks--) {
|
||||
uint randNumber = 0;
|
||||
for (int filled = 0; filled < intbits; filled += randbits)
|
||||
randNumber |= qrand()<<filled;
|
||||
*(data+chunks) = randNumber;
|
||||
}
|
||||
int chunks = 16 / sizeof(uint);
|
||||
while (chunks--) {
|
||||
uint randNumber = 0;
|
||||
for (int filled = 0; filled < intbits; filled += randbits)
|
||||
randNumber |= qrand()<<filled;
|
||||
*(data+chunks) = randNumber;
|
||||
}
|
||||
|
||||
result.data4[0] = (result.data4[0] & 0x3F) | 0x80; // UV_DCE
|
||||
|
|
Loading…
Add table
Reference in a new issue