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

ruby-changes:40347

From: normal <ko1@a...>
Date: Tue, 3 Nov 2015 07:18:56 +0900 (JST)
Subject: [ruby-changes:40347] normal:r52428 (trunk): id_table: const correctness for _size and _memsize

normal	2015-11-03 07:18:32 +0900 (Tue, 03 Nov 2015)

  New Revision: 52428

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

  Log:
    id_table: const correctness for _size and _memsize
    
    This allows us to swap in rb_id_table_memsize for st_memsize
    (which takes a "const st_table *") more easily.
    
    It also makes sense to do the same for rb_id_table_size,
    too; as the table cannot be altered when accessing size.
    
    * id_table.h (rb_id_table_size): const arg
      (rb_id_table_memsize): ditto
    * id_table.c (st_id_table_size): ditto
      (st_id_table_memsize): ditto
      (list_id_table_size): ditto
      (list_id_table_memsize): ditto
      (hash_id_table_size): ditto
      (hash_id_table_memsize): ditto
      (mix_id_table_size): ditto
      (mix_id_table_memsize): ditto

  Modified files:
    trunk/id_table.c
    trunk/id_table.h
Index: id_table.c
===================================================================
--- id_table.c	(revision 52427)
+++ id_table.c	(revision 52428)
@@ -200,8 +200,8 @@ https://github.com/ruby/ruby/blob/trunk/id_table.c#L200
 UNUSED(ID_TABLE_IMPL_TYPE *IMPL(_create)(size_t));
 UNUSED(void IMPL(_free)(ID_TABLE_IMPL_TYPE *));
 UNUSED(void IMPL(_clear)(ID_TABLE_IMPL_TYPE *));
-UNUSED(size_t IMPL(_size)(ID_TABLE_IMPL_TYPE *));
-UNUSED(size_t IMPL(_memsize)(ID_TABLE_IMPL_TYPE *));
+UNUSED(size_t IMPL(_size)(const ID_TABLE_IMPL_TYPE *));
+UNUSED(size_t IMPL(_memsize)(const ID_TABLE_IMPL_TYPE *));
 UNUSED(int IMPL(_insert)(ID_TABLE_IMPL_TYPE *, ID, VALUE));
 UNUSED(int IMPL(_lookup)(ID_TABLE_IMPL_TYPE *, ID, VALUE *));
 UNUSED(int IMPL(_delete)(ID_TABLE_IMPL_TYPE *, ID));
@@ -298,13 +298,13 @@ st_id_table_clear(struct st_id_table *tb https://github.com/ruby/ruby/blob/trunk/id_table.c#L298
 }
 
 static size_t
-st_id_table_size(struct st_id_table *tbl)
+st_id_table_size(const struct st_id_table *tbl)
 {
     return tbl2st(tbl)->num_entries;
 }
 
 static size_t
-st_id_table_memsize(struct st_id_table *tbl)
+st_id_table_memsize(const struct st_id_table *tbl)
 {
     size_t header_size = ID_TABLE_USE_ST_DEBUG ? sizeof(struct st_id_table) : 0;
     return header_size + st_memsize(tbl2st(tbl));
@@ -416,13 +416,13 @@ list_id_table_clear(struct list_id_table https://github.com/ruby/ruby/blob/trunk/id_table.c#L416
 }
 
 static size_t
-list_id_table_size(struct list_id_table *tbl)
+list_id_table_size(const struct list_id_table *tbl)
 {
     return (size_t)tbl->num;
 }
 
 static size_t
-list_id_table_memsize(struct list_id_table *tbl)
+list_id_table_memsize(const struct list_id_table *tbl)
 {
     return (sizeof(id_key_t) + sizeof(VALUE)) * tbl->capa + sizeof(struct list_id_table);
 }
@@ -821,7 +821,7 @@ hash_id_table_free(sa_table *table) https://github.com/ruby/ruby/blob/trunk/id_table.c#L821
 }
 
 static size_t
-hash_id_table_memsize(sa_table *table)
+hash_id_table_memsize(const sa_table *table)
 {
     return sizeof(sa_table) + table->num_bins * sizeof (sa_entry);
 }
@@ -1037,7 +1037,7 @@ hash_id_table_lookup(register sa_table * https://github.com/ruby/ruby/blob/trunk/id_table.c#L1037
 }
 
 static size_t
-hash_id_table_size(sa_table *table)
+hash_id_table_size(const sa_table *table)
 {
     return table->num_entries;
 }
@@ -1229,13 +1229,13 @@ hash_id_table_clear(struct hash_id_table https://github.com/ruby/ruby/blob/trunk/id_table.c#L1229
 }
 
 static size_t
-hash_id_table_size(struct hash_id_table *tbl)
+hash_id_table_size(const struct hash_id_table *tbl)
 {
     return (size_t)tbl->num;
 }
 
 static size_t
-hash_id_table_memsize(struct hash_id_table *tbl)
+hash_id_table_memsize(const struct hash_id_table *tbl)
 {
     return sizeof(item_t) * tbl->capa + sizeof(struct hash_id_table);
 }
@@ -1453,14 +1453,14 @@ mix_id_table_clear(struct mix_id_table * https://github.com/ruby/ruby/blob/trunk/id_table.c#L1453
 }
 
 static size_t
-mix_id_table_size(struct mix_id_table *tbl)
+mix_id_table_size(const struct mix_id_table *tbl)
 {
     if (LIST_P(tbl)) return list_id_table_size(&tbl->aux.list);
     else             return hash_id_table_size(&tbl->aux.hash);
 }
 
 static size_t
-mix_id_table_memsize(struct mix_id_table *tbl)
+mix_id_table_memsize(const struct mix_id_table *tbl)
 {
     if (LIST_P(tbl)) return list_id_table_memsize(&tbl->aux.list) - sizeof(struct list_id_table) + sizeof(struct mix_id_table);
     else             return hash_id_table_memsize(&tbl->aux.hash);
@@ -1553,8 +1553,8 @@ mix_id_table_foreach_values(struct mix_i https://github.com/ruby/ruby/blob/trunk/id_table.c#L1553
 IMPL_TYPE(struct rb_id_table *, create, (size_t size), (size))
 IMPL_VOID(free, (struct rb_id_table *tbl), (id_tbl))
 IMPL_VOID(clear, (struct rb_id_table *tbl), (id_tbl))
-IMPL_TYPE(size_t, size, (struct rb_id_table *tbl), (id_tbl))
-IMPL_TYPE(size_t, memsize, (struct rb_id_table *tbl), (id_tbl))
+IMPL_TYPE(size_t, size, (const struct rb_id_table *tbl), (id_tbl))
+IMPL_TYPE(size_t, memsize, (const struct rb_id_table *tbl), (id_tbl))
 
 IMPL_TYPE(int , insert, (struct rb_id_table *tbl, ID id, VALUE val),
 	  (id_tbl, id, val))
Index: id_table.h
===================================================================
--- id_table.h	(revision 52427)
+++ id_table.h	(revision 52428)
@@ -15,8 +15,8 @@ struct rb_id_table *rb_id_table_create(s https://github.com/ruby/ruby/blob/trunk/id_table.h#L15
 void rb_id_table_free(struct rb_id_table *tbl);
 void rb_id_table_clear(struct rb_id_table *tbl);
 
-size_t rb_id_table_size(struct rb_id_table *tbl);
-size_t rb_id_table_memsize(struct rb_id_table *tbl);
+size_t rb_id_table_size(const struct rb_id_table *tbl);
+size_t rb_id_table_memsize(const struct rb_id_table *tbl);
 
 int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val);
 int rb_id_table_lookup(struct rb_id_table *tbl, ID id, VALUE *valp);

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

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