summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-06-12 23:46:47 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-06-12 23:46:47 (GMT)
commit04d108111fe7ddd01713b4ca22f8d96961ec2486 (patch)
tree72ca086e0db2568bc93acb865b84e29c7d206897 /src/arch
parent64aee7b4301e720a7420ab8942ef88f72d7a2c99 (diff)
Improved loading speed with binary search of sorted arrays.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@538 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/processor.c54
1 files changed, 7 insertions, 47 deletions
diff --git a/src/arch/processor.c b/src/arch/processor.c
index 25a38b4..2c86ffe 100644
--- a/src/arch/processor.c
+++ b/src/arch/processor.c
@@ -381,62 +381,22 @@ GArchInstruction *g_arch_processor_get_disassembled_instructions(const GArchProc
GArchInstruction *g_arch_processor_find_instr_by_address(const GArchProcessor *proc, const vmpa2t *addr)
{
GArchInstruction *result; /* Trouvaille à retourner */
- GArchInstruction *fake; /* Coquille vide à comparer */
void *ptr; /* Résultat des recherches */
- size_t i; /* Boucle de parcours */
- const mrange_t *range; /* Emplacement d'instruction */
- if (has_phys_addr(addr))
+ int search_for_instr_by_addr(const vmpa2t *a, const GArchInstruction **b)
{
- fake = g_raw_instruction_new_from_value(addr, MDS_8_BITS_UNSIGNED, 0);
+ const mrange_t *range_b; /* Emplacement pour l'instr. B */
- int search_for_instr_by_addr(const GArchInstruction **a, const GArchInstruction **b)
- {
- const mrange_t *range_a; /* Emplacement pour l'instr. A */
- const mrange_t *range_b; /* Emplacement pour l'instr. B */
-
- range_a = g_arch_instruction_get_range(*a);
- range_b = g_arch_instruction_get_range(*b);
-
- /*
- printf(" -- cmp -- 0x%08x vs 0x%08x => %d\n",
- (unsigned int)range_a->addr.virtual,
- (unsigned int)range_b->addr.virtual,
- cmp_vmpa(get_mrange_addr(range_a), get_mrange_addr(range_b)));
- */
+ range_b = g_arch_instruction_get_range(*b);
- return cmp_vmpa(get_mrange_addr(range_a), get_mrange_addr(range_b));
-
- }
-
- ptr = bsearch(&fake, proc->instructions, proc->instr_count,
- sizeof(GArchInstruction *), (__compar_fn_t)search_for_instr_by_addr);
-
- g_object_unref(G_OBJECT(fake));
-
- result = (ptr != NULL ? *((GArchInstruction **)ptr) : NULL);
+ return cmp_vmpa(a, get_mrange_addr(range_b));
}
- else
- {
- result = NULL;
-
- for (i = 0; i < proc->instr_count && result == NULL; i++)
- {
- range = g_arch_instruction_get_range(proc->instructions[i]);
-
- if (cmp_vmpa(addr, get_mrange_addr(range)) == 0)
- result = proc->instructions[i];
+ ptr = bsearch(addr, proc->instructions, proc->instr_count,
+ sizeof(GArchInstruction *), (__compar_fn_t)search_for_instr_by_addr);
- }
-
- /*
- for (i = 0; i < proc->instr_count; i++)
- printf(" # %04zu 0x%08x\n", i, proc->instructions[i]->range.addr.virtual);
- */
-
- }
+ result = (ptr != NULL ? *((GArchInstruction **)ptr) : NULL);
return result;