cache the last entry of mapped blocks in memory_mapping() for better performance

This commit is contained in:
Nguyen Anh Quynh
2015-09-04 15:40:47 +08:00
parent fabbc0f4dc
commit d506b900eb
2 changed files with 11 additions and 1 deletions

11
uc.c
View File

@ -798,9 +798,18 @@ MemoryRegion *memory_mapping(struct uc_struct* uc, uint64_t address)
{
unsigned int i;
// try with the cache index first
i = uc->mapped_block_cache_index;
if (address >= uc->mapped_blocks[i]->addr && address < uc->mapped_blocks[i]->end)
return uc->mapped_blocks[i];
for(i = 0; i < uc->mapped_block_count; i++) {
if (address >= uc->mapped_blocks[i]->addr && address < uc->mapped_blocks[i]->end)
if (address >= uc->mapped_blocks[i]->addr && address < uc->mapped_blocks[i]->end) {
// cache this index for the next query
uc->mapped_block_cache_index = i;
return uc->mapped_blocks[i];
}
}
// not found