diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-05 22:40:32 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-05 22:40:32 +0000 |
commit | 93583166c8cc9b28d36d8f4f8e23fe968849498c (patch) | |
tree | 9dcba8a2fc55c2040e19638afacf690d9af8937b /hash.c | |
parent | 70caae18f26fb305b73ca33e71c46f370c3e0d20 (diff) | |
download | ruby-93583166c8cc9b28d36d8f4f8e23fe968849498c.tar.gz |
refactoring.
* hash.c (EQUAL, PTR_EQUAL): make corresponding inline functions
ar_equal() and ar_ptr_equal().
* hash.c (SET_*): removed. set fields directly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 36 |
1 files changed, 22 insertions, 14 deletions
@@ -307,17 +307,9 @@ static const struct st_hash_type identhash = { rb_ident_hash, }; -#define EQUAL(x,y) ((x) == (y) || rb_any_cmp((x),(y)) == 0) -#define PTR_EQUAL(ptr, hash_val, key_) \ - ((ptr)->hash == (hash_val) && EQUAL((key_), (ptr)->key)) - #define RESERVED_HASH_VAL (~(st_hash_t) 0) #define RESERVED_HASH_SUBSTITUTION_VAL ((st_hash_t) 0) -#define SET_KEY(entry, _key) (entry)->key = (_key) -#define SET_HASH(entry, _hash) (entry)->hash = (_hash) -#define SET_RECORD(entry, _value) (entry)->record = (_value) - typedef st_index_t st_hash_t; extern const st_hash_t st_reserved_hash_val; extern const st_hash_t st_reserved_hash_substitution_val; @@ -361,17 +353,17 @@ ar_do_hash(st_data_t key) static inline void ar_set_entry(ar_table_entry *entry, st_data_t key, st_data_t val, st_hash_t hash) { - SET_HASH(entry, hash); - SET_KEY(entry, key); - SET_RECORD(entry, val); + entry->hash = hash; + entry->key = key; + entry->record = val; } static inline void ar_clear_entry(ar_table_entry* entry) { - SET_KEY(entry, Qundef); - SET_RECORD(entry, Qundef); - SET_HASH(entry, RESERVED_HASH_VAL); + entry->key = Qundef; + entry->record = Qundef; + entry->hash = RESERVED_HASH_VAL; } static inline int @@ -595,6 +587,22 @@ ar_alloc_table(VALUE hash) return tab; } +#define EQUAL(x,y) ((x) == (y) || rb_any_cmp((x),(y)) == 0) +#define PTR_EQUAL(ptr, hash_val, key_) \ + ((ptr)->hash == (hash_val) && EQUAL((key_), (ptr)->key)) + +static inline int +ar_equal(VALUE x, VALUE y) +{ + return x == y || rb_any_cmp(x, y) == 0; +} + +static inline int +ar_ptr_equal(ar_table_entry *entry, st_hash_t hash_val, VALUE key) +{ + return entry->hash == hash_val && ar_equal(key, entry->key); +} + static unsigned ar_find_entry(VALUE hash, st_hash_t hash_value, st_data_t key) { |