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

ruby-changes:54550

From: ko1 <ko1@a...>
Date: Thu, 10 Jan 2019 04:11:41 +0900 (JST)
Subject: [ruby-changes:54550] ko1:r66765 (trunk): add setter of iter_lev.

ko1	2019-01-10 04:11:32 +0900 (Thu, 10 Jan 2019)

  New Revision: 66765

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

  Log:
    add setter of iter_lev.
    
    * hash.c: add special setter function (inc and dec).
    
    * internal.h: constify RHash::iter_leve.

  Modified files:
    trunk/hash.c
    trunk/internal.h
Index: internal.h
===================================================================
--- internal.h	(revision 66764)
+++ internal.h	(revision 66765)
@@ -806,7 +806,7 @@ struct RHash { https://github.com/ruby/ruby/blob/trunk/internal.h#L806
         st_table *st;
         struct ar_table_struct *ar; /* possibly 0 */
     } as;
-    int iter_lev;
+    const int iter_lev;
     const VALUE ifnone;
 };
 
Index: hash.c
===================================================================
--- hash.c	(revision 66764)
+++ hash.c	(revision 66765)
@@ -1206,17 +1206,29 @@ hash_foreach_iter(st_data_t key, st_data https://github.com/ruby/ruby/blob/trunk/hash.c#L1206
     return ST_CHECK;
 }
 
+static void
+hash_iter_lev_inc(VALUE hash)
+{
+    *((int *)&RHASH(hash)->iter_lev) = RHASH_ITER_LEV(hash) + 1;
+}
+
+static void
+hash_iter_lev_dec(VALUE hash)
+{
+    *((int *)&RHASH(hash)->iter_lev) = RHASH_ITER_LEV(hash) - 1;
+}
+
 static VALUE
 hash_foreach_ensure_rollback(VALUE hash)
 {
-    RHASH_ITER_LEV(hash)++;
+    hash_iter_lev_inc(hash);
     return 0;
 }
 
 static VALUE
 hash_foreach_ensure(VALUE hash)
 {
-    RHASH_ITER_LEV(hash)--;
+    hash_iter_lev_dec(hash);
     return 0;
 }
 
@@ -1257,7 +1269,7 @@ rb_hash_foreach(VALUE hash, int (*func)( https://github.com/ruby/ruby/blob/trunk/hash.c#L1269
 
     if (RHASH_TABLE_EMPTY_P(hash))
         return;
-    RHASH_ITER_LEV(hash)++;
+    hash_iter_lev_inc(hash);
     arg.hash = hash;
     arg.func = (rb_foreach_func *)func;
     arg.arg  = farg;

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

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