Bug 1461556 - Rename TypeSet::clone to TypeSet::cloneIntoUninitialized to indicate that it freshly initializes the TemporaryTypeSet* provided to it. Also removes existing code that, quite unnecessarily, partly initialized that argument. r=jandem

--HG--
extra : rebase_source : 2dcc8becf0ecdf8ea41bae4ad55439ddcfc7be21
This commit is contained in:
Jeff Walden 2018-05-16 19:29:57 -07:00
parent b1287bc521
commit 37589d31cd
2 changed files with 11 additions and 9 deletions

View File

@ -13,6 +13,8 @@
#include "mozilla/PodOperations.h"
#include "mozilla/Sprintf.h"
#include <new>
#include "jsapi.h"
#include "builtin/String.h"
@ -872,10 +874,8 @@ TypeSet::IsTypeAboutToBeFinalized(TypeSet::Type* v)
}
bool
TypeSet::clone(LifoAlloc* alloc, TemporaryTypeSet* result) const
TypeSet::cloneIntoUninitialized(LifoAlloc* alloc, TemporaryTypeSet* result) const
{
MOZ_ASSERT(result->empty());
unsigned objectCount = baseObjectCount();
unsigned capacity = (objectCount >= 2) ? TypeHashSet::Capacity(objectCount) : 0;
@ -890,15 +890,15 @@ TypeSet::clone(LifoAlloc* alloc, TemporaryTypeSet* result) const
PodCopy(newSet - 1, objectSet - 1, capacity + 1);
}
new(result) TemporaryTypeSet(flags, capacity ? newSet : objectSet);
new (result) TemporaryTypeSet(flags, capacity ? newSet : objectSet);
return true;
}
TemporaryTypeSet*
TypeSet::clone(LifoAlloc* alloc) const
{
TemporaryTypeSet* res = alloc->new_<TemporaryTypeSet>();
if (!res || !clone(alloc, res))
TemporaryTypeSet* res = alloc->pod_malloc<TemporaryTypeSet>();
if (!res || !cloneIntoUninitialized(alloc, res))
return nullptr;
return res;
}
@ -1167,10 +1167,9 @@ TypeScript::FreezeTypeSets(CompilerConstraintList* constraints, JSScript* script
TemporaryTypeSet* types = alloc->newArrayUninitialized<TemporaryTypeSet>(count);
if (!types)
return false;
PodZero(types, count);
for (size_t i = 0; i < count; i++) {
if (!existing[i].clone(alloc, &types[i]))
if (!existing[i].cloneIntoUninitialized(alloc, &types[i]))
return false;
}

View File

@ -508,7 +508,10 @@ class TypeSet
// Clone a type set into an arbitrary allocator.
TemporaryTypeSet* clone(LifoAlloc* alloc) const;
bool clone(LifoAlloc* alloc, TemporaryTypeSet* result) const;
// |*result| is not even partly initialized when this function is called:
// this function placement-new's its contents into existence.
bool cloneIntoUninitialized(LifoAlloc* alloc, TemporaryTypeSet* result) const;
// Create a new TemporaryTypeSet where undefined and/or null has been filtered out.
TemporaryTypeSet* filter(LifoAlloc* alloc, bool filterUndefined, bool filterNull) const;