[前][次][番号順一覧][スレッド一覧]

ruby-changes:54516

From: ko1 <ko1@a...>
Date: Sun, 6 Jan 2019 07:40:38 +0900 (JST)
Subject: [ruby-changes:54516] ko1:r66731 (trunk): refactoring.

ko1	2019-01-06 07:40:32 +0900 (Sun, 06 Jan 2019)

  New Revision: 66731

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66731

  Log:
    refactoring.
    
    * hash.c (EQUAL, PTR_EQUAL): make corresponding inline functions
      ar_equal() and ar_ptr_equal().
    
    * hash.c (SET_*): removed. set fields directly.

  Modified files:
    trunk/hash.c
Index: hash.c
===================================================================
--- hash.c	(revision 66730)
+++ hash.c	(revision 66731)
@@ -307,17 +307,9 @@ static const struct st_hash_type identha https://github.com/ruby/ruby/blob/trunk/hash.c#L307
     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) https://github.com/ruby/ruby/blob/trunk/hash.c#L353
 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) https://github.com/ruby/ruby/blob/trunk/hash.c#L587
     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)
 {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]