From 8c7685d1bdff0508c8aba421910b09e70e1c34e8 Mon Sep 17 00:00:00 2001 From: Wang Di Date: Tue, 11 May 2010 13:58:48 -0400 Subject: [PATCH] b=22683 remove unnecessary check and assert in the cfs_hash function. o=Eric.Barton i=Robert.Read i=Di.Wang --- libcfs/include/libcfs/libcfs_hash.h | 58 +++++-------------------------------- libcfs/libcfs/hash.c | 6 ++++ 2 files changed, 14 insertions(+), 50 deletions(-) diff --git a/libcfs/include/libcfs/libcfs_hash.h b/libcfs/include/libcfs/libcfs_hash.h index 82673de..98f4f78 100644 --- a/libcfs/include/libcfs/libcfs_hash.h +++ b/libcfs/include/libcfs/libcfs_hash.h @@ -157,86 +157,44 @@ typedef struct cfs_hash_ops { #define CFS_HASH_DEBUG 0x0001 /* Enable expensive debug checks */ #define CFS_HASH_REHASH 0x0002 /* Enable dynamic hash resizing */ -#define CFS_HO(hs) (hs)->hs_ops #define CFS_HOP(hs, op) (hs)->hs_ops->hs_ ## op static inline unsigned cfs_hash_id(cfs_hash_t *hs, void *key, unsigned mask) { - LASSERT(hs); - LASSERT(CFS_HO(hs)); - LASSERT(CFS_HOP(hs, hash)); - return CFS_HOP(hs, hash)(hs, key, mask); } static inline void * cfs_hash_key(cfs_hash_t *hs, cfs_hlist_node_t *hnode) { - LASSERT(hs); - LASSERT(hnode); - LASSERT(CFS_HO(hs)); - LASSERT(CFS_HOP(hs, key)); - return CFS_HOP(hs, key)(hnode); } -/* Returns 1 on a match, - * XXX: This would be better if it returned, -1, 0, or 1 for - * <, =, > respectivly. It could then be used to implement - * a CFS_HASH_SORT feature flags which could keep each hash - * bucket in order. This would increase insertion times - * but could reduce lookup times for deep chains. Ideally, - * the rehash should keep chain depth short but if that - * ends up not being the case this would be a nice feature. - */ +/* Returns TRUE on a match. */ static inline int cfs_hash_compare(cfs_hash_t *hs, void *key, cfs_hlist_node_t *hnode) { - LASSERT(hs); - LASSERT(hnode); - LASSERT(CFS_HO(hs)); - - if (CFS_HOP(hs, compare)) - return CFS_HOP(hs, compare)(key, hnode); - - return -EOPNOTSUPP; + return CFS_HOP(hs, compare)(key, hnode); } static inline void * cfs_hash_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode) { - LASSERT(hs); - LASSERT(hnode); - LASSERT(CFS_HO(hs)); - - if (CFS_HOP(hs, get)) - return CFS_HOP(hs, get)(hnode); - - return NULL; + return CFS_HOP(hs, get)(hnode); } static inline void * cfs_hash_put(cfs_hash_t *hs, cfs_hlist_node_t *hnode) { - LASSERT(hs); - LASSERT(hnode); - LASSERT(CFS_HO(hs)); - - if (CFS_HOP(hs, put)) - return CFS_HOP(hs, put)(hnode); - - return NULL; + return CFS_HOP(hs, put)(hnode); } static inline void cfs_hash_exit(cfs_hash_t *hs, cfs_hlist_node_t *hnode) { - LASSERT(hs); - LASSERT(hnode); - LASSERT(CFS_HO(hs)); - - if (CFS_HOP(hs, exit)) + /* This is allowed to be a NOOP */ + if (CFS_HOP(hs, exit) != NULL) return CFS_HOP(hs, exit)(hnode); } @@ -246,7 +204,7 @@ __cfs_hash_key_validate(cfs_hash_t *hs, void *key, cfs_hlist_node_t *hnode) { if (unlikely(hs->hs_flags & CFS_HASH_DEBUG)) - LASSERT(cfs_hash_compare(hs, key, hnode) > 0); + LASSERT(cfs_hash_compare(hs, key, hnode)); } /* Validate hnode is in the correct bucket */ @@ -269,7 +227,7 @@ __cfs_hash_bucket_lookup(cfs_hash_t *hs, cfs_hlist_node_t *hnode; cfs_hlist_for_each(hnode, &hsb->hsb_head) - if (cfs_hash_compare(hs, key, hnode) > 0) + if (cfs_hash_compare(hs, key, hnode)) return hnode; return NULL; diff --git a/libcfs/libcfs/hash.c b/libcfs/libcfs/hash.c index e670172..ae2f640 100644 --- a/libcfs/libcfs/hash.c +++ b/libcfs/libcfs/hash.c @@ -106,6 +106,12 @@ cfs_hash_create(char *name, unsigned int cur_bits, LASSERT(name != NULL); LASSERT(ops != NULL); + /* The following ops are required for all hash table types */ + LASSERT(ops->hs_hash != NULL); + LASSERT(ops->hs_key != NULL); + LASSERT(ops->hs_compare != NULL); + LASSERT(ops->hs_get != NULL); + LASSERT(ops->hs_put != NULL); LASSERT(cur_bits > 0); LASSERT(max_bits >= cur_bits); -- 1.8.3.1