Deduplicate some code
Requires one more branch inside the loop, but that should not really matter performance wise. And it should expand to less code. Change-Id: I4619dd2a2e6fedf8d109009a5b6d7410ed89f1fb Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
73ddfa25b4
commit
8a984ab772
@ -439,33 +439,14 @@ struct Data
|
||||
spans = new Span[nSpans];
|
||||
seed = qGlobalQHashSeed();
|
||||
}
|
||||
Data(const Data &other)
|
||||
Data(const Data &other, size_t reserved = 0)
|
||||
: size(other.size),
|
||||
numBuckets(other.numBuckets),
|
||||
seed(other.seed)
|
||||
{
|
||||
size_t nSpans = (other.numBuckets + Span::LocalBucketMask) / Span::NEntries;
|
||||
spans = new Span[nSpans];
|
||||
|
||||
for (size_t s = 0; s < nSpans; ++s) {
|
||||
const Span &span = other.spans[s];
|
||||
for (size_t index = 0; index < Span::NEntries; ++index) {
|
||||
if (!span.hasNode(index))
|
||||
continue;
|
||||
const Node &n = span.at(index);
|
||||
iterator it{ this, s*Span::NEntries + index };
|
||||
Q_ASSERT(it.isUnused());
|
||||
|
||||
Node *newNode = spans[it.span()].insert(it.index());
|
||||
new (newNode) Node(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
Data(const Data &other, size_t reserved)
|
||||
: size(other.size),
|
||||
seed(other.seed)
|
||||
{
|
||||
numBuckets = GrowthPolicy::bucketsForCapacity(qMax(size, reserved));
|
||||
if (reserved)
|
||||
numBuckets = GrowthPolicy::bucketsForCapacity(qMax(size, reserved));
|
||||
bool resized = numBuckets != other.numBuckets;
|
||||
size_t nSpans = (numBuckets + Span::LocalBucketMask) / Span::NEntries;
|
||||
spans = new Span[nSpans];
|
||||
|
||||
@ -475,7 +456,7 @@ struct Data
|
||||
if (!span.hasNode(index))
|
||||
continue;
|
||||
const Node &n = span.at(index);
|
||||
iterator it = find(n.key);
|
||||
iterator it = resized ? find(n.key) : iterator{ this, s*Span::NEntries + index };
|
||||
Q_ASSERT(it.isUnused());
|
||||
Node *newNode = spans[it.span()].insert(it.index());
|
||||
new (newNode) Node(n);
|
||||
@ -483,16 +464,7 @@ struct Data
|
||||
}
|
||||
}
|
||||
|
||||
static Data *detached(Data *d)
|
||||
{
|
||||
if (!d)
|
||||
return new Data;
|
||||
Data *dd = new Data(*d);
|
||||
if (!d->ref.deref())
|
||||
delete d;
|
||||
return dd;
|
||||
}
|
||||
static Data *detached(Data *d, size_t size)
|
||||
static Data *detached(Data *d, size_t size = 0)
|
||||
{
|
||||
if (!d)
|
||||
return new Data(size);
|
||||
|
Loading…
Reference in New Issue
Block a user