FunctionHasExecutedCache.cpp [plain text]
#include "config.h"
#include "FunctionHasExecutedCache.h"
#include <limits.h>
namespace JSC {
bool FunctionHasExecutedCache::hasExecutedAtOffset(intptr_t id, unsigned offset)
{
if (m_rangeMap.find(id) == m_rangeMap.end())
return false;
RangeMap& map = m_rangeMap.find(id)->second;
unsigned distance = UINT_MAX;
bool hasExecuted = false;
for (auto iter = map.begin(), end = map.end(); iter != end; ++iter) {
const FunctionRange& range = iter->first;
if (range.m_start <= offset && offset <= range.m_end && range.m_end - range.m_start < distance) {
hasExecuted = iter->second;
distance = range.m_end - range.m_start;
}
}
return hasExecuted;
}
void FunctionHasExecutedCache::insertUnexecutedRange(intptr_t id, unsigned start, unsigned end)
{
if (m_rangeMap.find(id) == m_rangeMap.end()) {
RangeMap map;
m_rangeMap[id] = map;
}
RangeMap& map = m_rangeMap.find(id)->second;
FunctionRange range;
range.m_start = start;
range.m_end = end;
if (map.find(range) == map.end())
map[range] = false;
}
void FunctionHasExecutedCache::removeUnexecutedRange(intptr_t id, unsigned start, unsigned end)
{
if (m_rangeMap.find(id) == m_rangeMap.end())
return;
RangeMap& map = m_rangeMap.find(id)->second;
FunctionRange range;
range.m_start = start;
range.m_end = end;
map[range] = true;
}
Vector<std::tuple<bool, unsigned, unsigned>> FunctionHasExecutedCache::getFunctionRanges(intptr_t id)
{
Vector<std::tuple<bool, unsigned, unsigned>> ranges(0);
auto findResult = m_rangeMap.find(id);
if (findResult == m_rangeMap.end())
return ranges;
RangeMap& map = m_rangeMap.find(id)->second;
for (auto iter = map.begin(), end = map.end(); iter != end; ++iter) {
const FunctionRange& range = iter->first;
bool hasExecuted = iter->second;
ranges.append(std::tuple<bool, unsigned, unsigned>(hasExecuted, range.m_start, range.m_end));
}
return ranges;
}
}