From 3b8e32c9bbe0d909c34303da0ad36ef0ef5be852 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Fri, 9 Oct 2015 03:11:34 +0200 Subject: Introduce hashes --- pcilib/bank.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'pcilib/bank.c') diff --git a/pcilib/bank.c b/pcilib/bank.c index 66ff739..24ddf1f 100644 --- a/pcilib/bank.c +++ b/pcilib/bank.c @@ -208,6 +208,7 @@ pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const ch pcilib_register_t i; pcilib_register_bank_t bank_id; pcilib_register_bank_addr_t bank_addr = 0; + pcilib_register_context_t *reg_ctx; const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); const pcilib_register_description_t *registers = model_info->registers; @@ -220,11 +221,16 @@ pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const ch } bank_addr = model_info->banks[bank_id].addr; + + // ToDo: we can use additionaly per-bank hashes + for (i = 0; registers[i].bits; i++) { + if ((!strcasecmp(registers[i].name, reg))&&((!bank)||(registers[i].bank == bank_addr))) return i; + } + } else { + HASH_FIND_STR(ctx->reg_hash, reg, reg_ctx); + if (reg_ctx) return reg_ctx->reg; } - - for (i = 0; registers[i].bits; i++) { - if ((!strcasecmp(registers[i].name, reg))&&((!bank)||(registers[i].bank == bank_addr))) return i; - } + return PCILIB_REGISTER_INVALID; }; -- cgit v1.2.3