diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-12-18 21:36:14 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-12-18 21:36:14 (GMT) |
commit | d50544a3de540727137f2b13010ca4450f8ea10f (patch) | |
tree | 05e4ad65c25570016d5732f425a9eff2f4117d34 /src/arch/dalvik/operands | |
parent | b0bcf250999b2242019f137e38f52390a86e71cd (diff) |
Used a fast sorted array to track shared instances instead of a simple hash table.
Diffstat (limited to 'src/arch/dalvik/operands')
-rw-r--r-- | src/arch/dalvik/operands/args.c | 54 | ||||
-rw-r--r-- | src/arch/dalvik/operands/pool.c | 52 | ||||
-rw-r--r-- | src/arch/dalvik/operands/register.c | 51 |
3 files changed, 49 insertions, 108 deletions
diff --git a/src/arch/dalvik/operands/args.c b/src/arch/dalvik/operands/args.c index 9e75604..5ba552b 100644 --- a/src/arch/dalvik/operands/args.c +++ b/src/arch/dalvik/operands/args.c @@ -30,6 +30,7 @@ #include "../../operand-int.h" #include "../../sharing/manager.h" +#include "../../../common/sort.h" @@ -70,11 +71,8 @@ static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *); /* Initialise un nouvel objet partagé avec des informations. */ static bool g_dalvik_args_operand_do_init(GDalvikArgsOperand *, const GDalvikArgsOperand *); -/* Indique l'objet partagé correspond à une description donnée. */ -static gboolean g_dalvik_args_operand_compare_info(const GDalvikArgsOperand *, const GDalvikArgsOperand *); - /* Compare un opérande avec un autre. */ -static bool g_dalvik_args_operand_compare(const GDalvikArgsOperand *, const GDalvikArgsOperand *); +static int g_dalvik_args_operand_compare(const GDalvikArgsOperand * const *, const GDalvikArgsOperand * const *); /* Traduit un opérande en version humainement lisible. */ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine *, AsmSyntax); @@ -122,7 +120,6 @@ static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass) object->finalize = (GObjectFinalizeFunc)g_dalvik_args_operand_finalize; operand->init = (init_shared_fc)g_dalvik_args_operand_do_init; - operand->cmp_info = (compare_shared_info_fc)g_dalvik_args_operand_compare_info; operand->compare = (operand_compare_fc)g_dalvik_args_operand_compare; operand->print = (operand_print_fc)g_dalvik_args_operand_print; @@ -253,30 +250,6 @@ static bool g_dalvik_args_operand_do_init(GDalvikArgsOperand *operand, const GDa /****************************************************************************** * * -* Paramètres : operand = objet partagé à consulter. * -* fake = coquille vide contenant les infos à comparer. * -* * -* Description : Indique l'objet partagé correspond à une description donnée. * -* * -* Retour : TRUE si les détails centraux sont partagés, FALSE sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static gboolean g_dalvik_args_operand_compare_info(const GDalvikArgsOperand *operand, const GDalvikArgsOperand *fake) -{ - gboolean result; /* Bilan à retourner */ - - result = g_dalvik_args_operand_compare(operand, fake); - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : a = premier opérande à consulter. * * b = second opérande à consulter. * * * @@ -288,20 +261,26 @@ static gboolean g_dalvik_args_operand_compare_info(const GDalvikArgsOperand *ope * * ******************************************************************************/ -static bool g_dalvik_args_operand_compare(const GDalvikArgsOperand *a, const GDalvikArgsOperand *b) +static int g_dalvik_args_operand_compare(const GDalvikArgsOperand * const *a, const GDalvikArgsOperand * const *b) { - bool result; /* Bilan à renvoyer */ + int result; /* Bilan à renvoyer */ + const GDalvikArgsOperand *_a; /* Accès rapide à l'élément A */ + const GDalvikArgsOperand *_b; /* Accès rapide à l'élément B */ size_t i; /* Boucle de parcours */ - if (b == NULL) - result = (a->count == 0); + _a = *a; + _b = *b; + + if (_b == NULL) + result = sort_unsigned_long(_a->count, 0); else { - result = (a->count == b->count); + result = sort_unsigned_long(_a->count, _b->count); - for (i = 0; i < a->count && result; i++) - result = g_arch_operand_compare(a->args[i], b->args[i]); + for (i = 0; i < _a->count && result == 0; i++) + result = g_arch_operand_compare((const GArchOperand * const *)&_a->args[i], + (const GArchOperand * const *)&_b->args[i]); } @@ -377,7 +356,8 @@ GDalvikArgsOperand *g_dalvik_args_operand_add(GDalvikArgsOperand *operand, GArch fake.args[i] = arg; - result = g_share_manager_update(_dalvik_args_operand_manager, G_SHARED_INSTANCE(operand), &fake, container); + result = g_share_manager_update(_dalvik_args_operand_manager, G_SHARED_INSTANCE(operand), + (GSharedInstance *)&fake, container); free(fake.args); diff --git a/src/arch/dalvik/operands/pool.c b/src/arch/dalvik/operands/pool.c index 4884867..be38ca3 100644 --- a/src/arch/dalvik/operands/pool.c +++ b/src/arch/dalvik/operands/pool.c @@ -33,6 +33,7 @@ #include "../../operand-int.h" #include "../../sharing/manager.h" +#include "../../../common/sort.h" #include "../../../format/dex/pool.h" @@ -75,11 +76,8 @@ static void g_dalvik_pool_operand_finalize(GDalvikPoolOperand *); /* Initialise un nouvel objet partagé avec des informations. */ static bool g_dalvik_pool_operand_do_init(GDalvikPoolOperand *, const GDalvikPoolOperand *); -/* Indique l'objet partagé correspond à une description donnée. */ -static gboolean g_dalvik_pool_operand_compare_info(const GDalvikPoolOperand *, const GDalvikPoolOperand *); - /* Compare un opérande avec un autre. */ -static bool g_dalvik_pool_operand_compare(const GDalvikPoolOperand *, const GDalvikPoolOperand *); +static int g_dalvik_pool_operand_compare(const GDalvikPoolOperand * const *, const GDalvikPoolOperand * const *); /* Traduit un opérande en version humainement lisible. */ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *, GBufferLine *, AsmSyntax); @@ -128,7 +126,6 @@ static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *klass) operand = G_ARCH_OPERAND_CLASS(klass); operand->init = (init_shared_fc)g_dalvik_pool_operand_do_init; - operand->cmp_info = (compare_shared_info_fc)g_dalvik_pool_operand_compare_info; operand->compare = (operand_compare_fc)g_dalvik_pool_operand_compare; operand->print = (operand_print_fc)g_dalvik_pool_operand_print; @@ -241,7 +238,7 @@ GArchOperand *g_dalvik_pool_operand_new(GDexFormat *format, DalvikPoolType type, fake.type = type; fake.index = (size == MDS_8_BITS ? index8 : index16); - result = G_ARCH_OPERAND(g_share_manager_get(_dalvik_pool_operand_manager, &fake)); + result = G_ARCH_OPERAND(g_share_manager_get(_dalvik_pool_operand_manager, (GSharedInstance *)&fake)); gdpon_exit: @@ -278,30 +275,6 @@ static bool g_dalvik_pool_operand_do_init(GDalvikPoolOperand *operand, const GDa /****************************************************************************** * * -* Paramètres : operand = objet partagé à consulter. * -* fake = coquille vide contenant les infos à comparer. * -* * -* Description : Indique l'objet partagé correspond à une description donnée. * -* * -* Retour : TRUE si les détails centraux sont partagés, FALSE sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static gboolean g_dalvik_pool_operand_compare_info(const GDalvikPoolOperand *operand, const GDalvikPoolOperand *fake) -{ - gboolean result; /* Bilan à retourner */ - - result = g_dalvik_pool_operand_compare(operand, fake); - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : a = premier opérande à consulter. * * b = second opérande à consulter. * * * @@ -313,13 +286,22 @@ static gboolean g_dalvik_pool_operand_compare_info(const GDalvikPoolOperand *ope * * ******************************************************************************/ -static bool g_dalvik_pool_operand_compare(const GDalvikPoolOperand *a, const GDalvikPoolOperand *b) +static int g_dalvik_pool_operand_compare(const GDalvikPoolOperand * const *a, const GDalvikPoolOperand * const *b) { - bool result; /* Bilan à renvoyer */ + int result; /* Bilan à renvoyer */ + const GDalvikPoolOperand *_a; /* Accès rapide à l'élément A */ + const GDalvikPoolOperand *_b; /* Accès rapide à l'élément B */ + + _a = *a; + _b = *b; + + result = sort_unsigned_long((unsigned long)_a->format, (unsigned long)_b->format); + + if (result == 0) + result = sort_unsigned_long(_a->type, _b->type); - result = (a->format == b->format); - result &= (a->type == b->type); - result &= (a->index == b->index); + if (result == 0) + result = sort_unsigned_long(_a->index, _b->index); return result; diff --git a/src/arch/dalvik/operands/register.c b/src/arch/dalvik/operands/register.c index dcdcbac..613e0d4 100644 --- a/src/arch/dalvik/operands/register.c +++ b/src/arch/dalvik/operands/register.c @@ -65,13 +65,10 @@ static void g_dalvik_register_operand_dispose(GDalvikRegisterOperand *); static void g_dalvik_register_operand_finalize(GDalvikRegisterOperand *); /* Initialise un nouvel objet partagé avec des informations. */ -static bool g_dalvik_register_operand_do_init(GDalvikRegisterOperand *, const GDalvikRegister *); - -/* Indique l'objet partagé correspond à une description donnée. */ -static gboolean g_dalvik_register_operand_compare_info(const GDalvikRegisterOperand *, const GDalvikRegister *); +static bool g_dalvik_register_operand_do_init(GDalvikRegisterOperand *, const GDalvikRegisterOperand *); /* Compare un opérande avec un autre. */ -static bool g_dalvik_register_operand_compare(const GDalvikRegisterOperand *, const GDalvikRegisterOperand *); +static int g_dalvik_register_operand_compare(const GDalvikRegisterOperand * const *, const GDalvikRegisterOperand * const *); /* Traduit un opérande en version humainement lisible. */ static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *, GBufferLine *, AsmSyntax); @@ -120,7 +117,6 @@ static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *kl operand = G_ARCH_OPERAND_CLASS(klass); operand->init = (init_shared_fc)g_dalvik_register_operand_do_init; - operand->cmp_info = (compare_shared_info_fc)g_dalvik_register_operand_compare_info; operand->compare = (operand_compare_fc)g_dalvik_register_operand_compare; operand->print = (operand_print_fc)g_dalvik_register_operand_print; @@ -275,8 +271,11 @@ GArchOperand *g_dalvik_register_operand_new(const GBinContent *content, vmpa2t * GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *reg) { GArchOperand *result; /* Structure à retourner */ + GDalvikRegisterOperand fake; /* Transport d'informations */ + + fake.reg = reg; - result = G_ARCH_OPERAND(g_share_manager_get(_dalvik_register_operand_manager, reg)); + result = G_ARCH_OPERAND(g_share_manager_get(_dalvik_register_operand_manager, (GSharedInstance *)&fake)); return result; @@ -286,7 +285,7 @@ GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *reg) /****************************************************************************** * * * Paramètres : operand = objet partagé à initialiser. * -* reg = registre Dalvik à associer à l'opérande. * +* fake = coquille vide contenant les infos à enregistrer. * * * * Description : Initialise un nouvel objet partagé avec des informations. * * * @@ -296,9 +295,9 @@ GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *reg) * * ******************************************************************************/ -static bool g_dalvik_register_operand_do_init(GDalvikRegisterOperand *operand, const GDalvikRegister *reg) +static bool g_dalvik_register_operand_do_init(GDalvikRegisterOperand *operand, const GDalvikRegisterOperand *fake) { - operand->reg = reg; + operand->reg = fake->reg; return true; @@ -307,30 +306,6 @@ static bool g_dalvik_register_operand_do_init(GDalvikRegisterOperand *operand, c /****************************************************************************** * * -* Paramètres : operand = objet partagé à consulter. * -* reg = registre Dalvik utilisé comme description. * -* * -* Description : Indique l'objet partagé correspond à une description donnée. * -* * -* Retour : TRUE si les détails centraux sont partagés, FALSE sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static gboolean g_dalvik_register_operand_compare_info(const GDalvikRegisterOperand *operand, const GDalvikRegister *reg) -{ - gboolean result; /* Bilan à retourner */ - - result = g_arch_register_equal(G_ARCH_REGISTER(operand->reg), G_ARCH_REGISTER(reg)); - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : a = premier opérande à consulter. * * b = second opérande à consulter. * * * @@ -342,9 +317,13 @@ static gboolean g_dalvik_register_operand_compare_info(const GDalvikRegisterOper * * ******************************************************************************/ -static bool g_dalvik_register_operand_compare(const GDalvikRegisterOperand *a, const GDalvikRegisterOperand *b) +static int g_dalvik_register_operand_compare(const GDalvikRegisterOperand * const *a, const GDalvikRegisterOperand * const *b) { - return (g_arch_register_compare(G_ARCH_REGISTER(a->reg), G_ARCH_REGISTER(b->reg)) == 0); + int result; /* Bilan à retourner */ + + result = g_dalvik_register_compare(&(*a)->reg, &(*b)->reg); + + return result; } |