ArrayAllocationProfile.h [plain text]
#pragma once
#include "IndexingType.h"
#include "JSArray.h"
namespace JSC {
class ArrayAllocationProfile {
public:
ArrayAllocationProfile() = default;
ArrayAllocationProfile(IndexingType recommendedIndexingMode)
{
initializeIndexingMode(recommendedIndexingMode);
}
IndexingType selectIndexingType()
{
JSArray* lastArray = m_lastArray;
if (lastArray && UNLIKELY(lastArray->indexingType() != m_currentIndexingType))
updateProfile();
return m_currentIndexingType;
}
unsigned vectorLengthHint()
{
JSArray* lastArray = m_lastArray;
if (lastArray && (m_largestSeenVectorLength != BASE_CONTIGUOUS_VECTOR_LEN_MAX) && UNLIKELY(lastArray->getVectorLength() > m_largestSeenVectorLength))
updateProfile();
return m_largestSeenVectorLength;
}
JSArray* updateLastAllocation(JSArray* lastArray)
{
m_lastArray = lastArray;
return lastArray;
}
JS_EXPORT_PRIVATE void updateProfile();
static IndexingType selectIndexingTypeFor(ArrayAllocationProfile* profile)
{
if (!profile)
return ArrayWithUndecided;
return profile->selectIndexingType();
}
static JSArray* updateLastAllocationFor(ArrayAllocationProfile* profile, JSArray* lastArray)
{
if (profile)
profile->updateLastAllocation(lastArray);
return lastArray;
}
void initializeIndexingMode(IndexingType recommendedIndexingMode) { m_currentIndexingType = recommendedIndexingMode; }
private:
IndexingType m_currentIndexingType { ArrayWithUndecided };
unsigned m_largestSeenVectorLength { 0 };
JSArray* m_lastArray { nullptr };
};
}