cache the last entry of mapped blocks in memory_mapping() for better performance
This commit is contained in:
@ -175,6 +175,7 @@ struct uc_struct {
|
|||||||
bool block_full;
|
bool block_full;
|
||||||
MemoryRegion **mapped_blocks;
|
MemoryRegion **mapped_blocks;
|
||||||
uint32_t mapped_block_count;
|
uint32_t mapped_block_count;
|
||||||
|
uint32_t mapped_block_cache_index;
|
||||||
void *qemu_thread_data; // to support cross compile to Windows (qemu-thread-win32.c)
|
void *qemu_thread_data; // to support cross compile to Windows (qemu-thread-win32.c)
|
||||||
uint32_t target_page_size;
|
uint32_t target_page_size;
|
||||||
uint32_t target_page_align;
|
uint32_t target_page_align;
|
||||||
|
11
uc.c
11
uc.c
@ -798,9 +798,18 @@ MemoryRegion *memory_mapping(struct uc_struct* uc, uint64_t address)
|
|||||||
{
|
{
|
||||||
unsigned int i;
|
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++) {
|
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];
|
return uc->mapped_blocks[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// not found
|
// not found
|
||||||
|
Reference in New Issue
Block a user