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

ruby-changes:54628

From: ko1 <ko1@a...>
Date: Thu, 17 Jan 2019 16:52:53 +0900 (JST)
Subject: [ruby-changes:54628] ko1:r66843 (trunk): reset bound if the size is 0.

ko1	2019-01-17 16:52:47 +0900 (Thu, 17 Jan 2019)

  New Revision: 66843

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

  Log:
    reset bound if the size is 0.
    
    * hash.c (RHASH_AR_TABLE_SIZE_DEC): generally, we need to check all
      entries to calculate exact "bound" in ar_table, but if size == 0,
      we can clear bound because there are no active entries.

  Modified files:
    trunk/hash.c
Index: hash.c
===================================================================
--- hash.c	(revision 66842)
+++ hash.c	(revision 66843)
@@ -554,11 +554,21 @@ hash_ar_table_set(VALUE hash, ar_table * https://github.com/ruby/ruby/blob/trunk/hash.c#L554
 } while (0)
 
 #define RHASH_AR_TABLE_SIZE_INC(h) HASH_AR_TABLE_SIZE_ADD(h, 1)
-#define RHASH_AR_TABLE_SIZE_DEC(h) do  { \
-    HASH_ASSERT(RHASH_AR_TABLE_P(h)); \
-    RHASH_AR_TABLE_SIZE_SET((h), RHASH_AR_TABLE_SIZE(h) - 1); \
-    hash_verify(h); \
-} while (0)
+
+static inline void
+RHASH_AR_TABLE_SIZE_DEC(VALUE h) {
+    HASH_ASSERT(RHASH_AR_TABLE_P(h));
+    int new_size = RHASH_AR_TABLE_SIZE(h) - 1;
+
+    if (new_size != 0) {
+        RHASH_AR_TABLE_SIZE_SET(h, new_size);
+    }
+    else {
+        RHASH_AR_TABLE_SIZE_SET(h, 0);
+        RHASH_AR_TABLE_BOUND_SET(h, 0);
+    }
+    hash_verify(h);
+}
 
 #define RHASH_AR_TABLE_CLEAR(h) do { \
     RBASIC(h)->flags &= ~RHASH_AR_TABLE_SIZE_MASK; \

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

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