DFGDesiredIdentifiers.cpp [plain text]
#include "config.h"
#include "DFGDesiredIdentifiers.h"
#if ENABLE(DFG_JIT)
#include "CodeBlock.h"
#include "DFGCommonData.h"
#include "JSCInlines.h"
namespace JSC { namespace DFG {
DesiredIdentifiers::DesiredIdentifiers()
: m_codeBlock(nullptr)
, m_didProcessIdentifiers(false)
{
}
DesiredIdentifiers::DesiredIdentifiers(CodeBlock* codeBlock)
: m_codeBlock(codeBlock)
, m_didProcessIdentifiers(false)
{
}
DesiredIdentifiers::~DesiredIdentifiers()
{
}
unsigned DesiredIdentifiers::numberOfIdentifiers()
{
return m_codeBlock->numberOfIdentifiers() + m_addedIdentifiers.size();
}
unsigned DesiredIdentifiers::ensure(UniquedStringImpl* rep)
{
if (!m_didProcessIdentifiers) {
for (unsigned index = m_codeBlock->numberOfIdentifiers(); index--;)
m_identifierNumberForName.add(m_codeBlock->identifier(index).impl(), index);
m_didProcessIdentifiers = true;
}
auto addResult = m_identifierNumberForName.add(rep, numberOfIdentifiers());
unsigned result = addResult.iterator->value;
if (addResult.isNewEntry) {
m_addedIdentifiers.append(rep);
ASSERT(at(result) == rep);
}
return result;
}
UniquedStringImpl* DesiredIdentifiers::at(unsigned index) const
{
UniquedStringImpl* result;
if (index < m_codeBlock->numberOfIdentifiers())
result = m_codeBlock->identifier(index).impl();
else
result = m_addedIdentifiers[index - m_codeBlock->numberOfIdentifiers()];
ASSERT(result->hasAtLeastOneRef());
return result;
}
void DesiredIdentifiers::reallyAdd(VM& vm, CommonData* commonData)
{
for (auto rep : m_addedIdentifiers) {
ASSERT(rep->hasAtLeastOneRef());
commonData->dfgIdentifiers.append(Identifier::fromUid(&vm, rep));
}
}
} }
#endif // ENABLE(DFG_JIT)