Skip to content

Commit

Permalink
Merge r220500 - [JSC] Create JSSet constructor that accepts it's size…
Browse files Browse the repository at this point in the history
… as parameter

https://bugs.webkit.org/show_bug.cgi?id=173297

Reviewed by Saam Barati.

This patch is adding a new constructor to JSSet that gives its
expected initial size. It is important to avoid re-hashing and mutiple
allocations when we know the final size of JSSet, such as in
CodeBlock::setConstantIdentifierSetRegisters.

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::setConstantIdentifierSetRegisters):
* runtime/HashMapImpl.h:
(JSC::HashMapImpl::HashMapImpl):
* runtime/JSSet.h:
  • Loading branch information
caiolima authored and carlosgcampos committed Aug 14, 2017
1 parent ae6d2f9 commit 4bcc2e2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
18 changes: 18 additions & 0 deletions Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,21 @@
2017-08-09 Caio Lima <ticaiolima@gmail.com>

[JSC] Create JSSet constructor that accepts it's size as parameter
https://bugs.webkit.org/show_bug.cgi?id=173297

Reviewed by Saam Barati.

This patch is adding a new constructor to JSSet that gives its
expected initial size. It is important to avoid re-hashing and mutiple
allocations when we know the final size of JSSet, such as in
CodeBlock::setConstantIdentifierSetRegisters.

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::setConstantIdentifierSetRegisters):
* runtime/HashMapImpl.h:
(JSC::HashMapImpl::HashMapImpl):
* runtime/JSSet.h:

2017-08-09 Caitlin Potter <caitp@igalia.com>

Early error on ANY operator before new.target
Expand Down
5 changes: 3 additions & 2 deletions Source/JavaScriptCore/bytecode/CodeBlock.cpp
Expand Up @@ -877,12 +877,13 @@ void CodeBlock::setConstantIdentifierSetRegisters(VM& vm, const Vector<ConstantI
ExecState* exec = globalObject->globalExec();

for (const auto& entry : constants) {
const IdentifierSet& set = entry.first;

Structure* setStructure = globalObject->setStructure();
RETURN_IF_EXCEPTION(scope, void());
JSSet* jsSet = JSSet::create(exec, vm, setStructure);
JSSet* jsSet = JSSet::create(exec, vm, setStructure, set.size());
RETURN_IF_EXCEPTION(scope, void());

const IdentifierSet& set = entry.first;
for (auto setEntry : set) {
JSString* jsString = jsOwnedString(&vm, setEntry.get());
jsSet->add(exec, jsString);
Expand Down
10 changes: 10 additions & 0 deletions Source/JavaScriptCore/runtime/HashMapImpl.h
Expand Up @@ -300,6 +300,16 @@ class HashMapImpl : public JSNonFinalObject {
{
}

HashMapImpl(VM& vm, Structure* structure, uint32_t sizeHint)
: Base(vm, structure)
, m_keyCount(0)
, m_deleteCount(0)
{
uint32_t capacity = ((Checked<uint32_t>(sizeHint) * 2) + 1).unsafeGet();
capacity = std::max<uint32_t>(WTF::roundUpToPowerOfTwo(capacity), 4U);
m_capacity = capacity;
}

ALWAYS_INLINE HashMapBucketType** buffer() const
{
return m_buffer->buffer();
Expand Down
12 changes: 11 additions & 1 deletion Source/JavaScriptCore/runtime/JSSet.h
Expand Up @@ -47,7 +47,12 @@ class JSSet final : public HashMapImpl<HashMapBucket<HashMapBucketDataKey>> {

static JSSet* create(ExecState* exec, VM& vm, Structure* structure)
{
JSSet* instance = new (NotNull, allocateCell<JSSet>(vm.heap)) JSSet(vm, structure);
return create(exec, vm, structure, 0);
}

static JSSet* create(ExecState* exec, VM& vm, Structure* structure, uint32_t size)
{
JSSet* instance = new (NotNull, allocateCell<JSSet>(vm.heap)) JSSet(vm, structure, size);
instance->finishCreation(exec, vm);
return instance;
}
Expand All @@ -62,6 +67,11 @@ class JSSet final : public HashMapImpl<HashMapBucket<HashMapBucketDataKey>> {
{
}

JSSet(VM& vm, Structure* structure, uint32_t sizeHint)
: Base(vm, structure, sizeHint)
{
}

static String toStringName(const JSObject*, ExecState*);
};

Expand Down

0 comments on commit 4bcc2e2

Please sign in to comment.