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

ruby-changes:38983

From: normal <ko1@a...>
Date: Tue, 30 Jun 2015 03:10:23 +0900 (JST)
Subject: [ruby-changes:38983] normal:r51064 (trunk): st.c: use ccan linked-list (try 3)

normal	2015-06-30 03:10:00 +0900 (Tue, 30 Jun 2015)

  New Revision: 51064

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

  Log:
    st.c: use ccan linked-list (try 3)
    
    This improves the bm_vm2_bighash benchmark significantly by
    removing branches during insert, but slows down anything
    requiring iteration with the more complex loop termination
    checking.
    
    Speedup ratio of 1.10 - 1.20 is typical for the vm2_bighash
    benchmark.
    
    v3 - st_head calculates list_head address in two steps
         to avoid a bug in old gcc 4.4 (Debian 4.4.7-2)
         bug which incorrectly warned with:
         warning: dereferencing pointer ?\226?\128?\152({anonymous})?\226?\128?\153 does break
         strict-aliasing rules
    
    * include/ruby/st.h (struct st_table): hide struct list_head
    * st.c (struct st_table_entry): adjust struct
      (head, tail): remove shortcut macros
      (st_head): new wrapper function
      (st_init_table_with_size): adjust to new struct and API
      (st_clear): ditto
      (add_direct): ditto
      (unpack_entries): ditto
      (rehash): ditto
      (st_copy): ditto
      (remove_entry): ditto
      (st_shift): ditto
      (st_foreach_check): ditto
      (st_foreach): ditto
      (get_keys): ditto
      (get_values): ditto
      (st_values_check): ditto
      (st_reverse_foreach_check): ditto (unused)
      (st_reverse_foreach): ditto (unused)
      [ruby-core:69726] [Misc #10278]

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/st.h
    trunk/st.c
Index: include/ruby/st.h
===================================================================
--- include/ruby/st.h	(revision 51063)
+++ include/ruby/st.h	(revision 51064)
@@ -86,7 +86,7 @@ struct st_table { https://github.com/ruby/ruby/blob/trunk/include/ruby/st.h#L86
     union {
 	struct {
 	    struct st_table_entry **bins;
-	    struct st_table_entry *head, *tail;
+	    void *private_list_head[2];
 	} big;
 	struct {
 	    struct st_packed_entry *entries;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51063)
+++ ChangeLog	(revision 51064)
@@ -1,3 +1,26 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jun 30 02:47:02 2015  Eric Wong  <e@8...>
+
+	* include/ruby/st.h (struct st_table): hide struct list_head
+	* st.c (struct st_table_entry): adjust struct
+	  (head, tail): remove shortcut macros
+	  (st_head): new wrapper function
+	  (st_init_table_with_size): adjust to new struct and API
+	  (st_clear): ditto
+	  (add_direct): ditto
+	  (unpack_entries): ditto
+	  (rehash): ditto
+	  (st_copy): ditto
+	  (remove_entry): ditto
+	  (st_shift): ditto
+	  (st_foreach_check): ditto
+	  (st_foreach): ditto
+	  (get_keys): ditto
+	  (get_values): ditto
+	  (st_values_check): ditto
+	  (st_reverse_foreach_check): ditto (unused)
+	  (st_reverse_foreach): ditto (unused)
+	  [ruby-core:69726] [Misc #10278]
+
 Mon Jun 29 17:38:01 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* insns.def (defineclass): do not quote unprintable characters at
Index: st.c
===================================================================
--- st.c	(revision 51063)
+++ st.c	(revision 51064)
@@ -23,7 +23,7 @@ struct st_table_entry { https://github.com/ruby/ruby/blob/trunk/st.c#L23
     st_data_t key;
     st_data_t record;
     st_table_entry *next;
-    st_table_entry *fore, *back;
+    struct list_node olist;
 };
 
 typedef struct st_packed_entry {
@@ -108,8 +108,6 @@ st_realloc_bins(st_table_entry **bins, s https://github.com/ruby/ruby/blob/trunk/st.c#L108
 
 /* Shortcut */
 #define bins as.big.bins
-#define head as.big.head
-#define tail as.big.tail
 #define real_entries as.packed.real_entries
 
 /* preparation for possible packing improvements */
@@ -195,6 +193,13 @@ stat_col(void) https://github.com/ruby/ruby/blob/trunk/st.c#L193
 }
 #endif
 
+static struct list_head *
+st_head(const st_table *tbl)
+{
+    uintptr_t addr = (uintptr_t)&tbl->as.big.private_list_head;
+    return (struct list_head *)addr;
+}
+
 st_table*
 st_init_table_with_size(const struct st_hash_type *type, st_index_t size)
 {
@@ -220,14 +225,14 @@ st_init_table_with_size(const struct st_ https://github.com/ruby/ruby/blob/trunk/st.c#L225
     tbl->entries_packed = size <= MAX_PACKED_HASH;
     if (tbl->entries_packed) {
 	size = ST_DEFAULT_PACKED_TABLE_SIZE;
+	tbl->real_entries = 0;
     }
     else {
 	size = new_size(size);	/* round up to power-of-two */
+	list_head_init(st_head(tbl));
     }
     tbl->num_bins = size;
     tbl->bins = st_alloc_bins(size);
-    tbl->head = 0;
-    tbl->tail = 0;
 
     return tbl;
 }
@@ -278,7 +283,6 @@ void https://github.com/ruby/ruby/blob/trunk/st.c#L283
 st_clear(st_table *table)
 {
     register st_table_entry *ptr, *next;
-    st_index_t i;
 
     if (table->entries_packed) {
         table->num_entries = 0;
@@ -286,18 +290,13 @@ st_clear(st_table *table) https://github.com/ruby/ruby/blob/trunk/st.c#L290
         return;
     }
 
-    for (i = 0; i < table->num_bins; i++) {
-	ptr = table->bins[i];
-	table->bins[i] = 0;
-	while (ptr != 0) {
-	    next = ptr->next;
-	    st_free_entry(ptr);
-	    ptr = next;
-	}
+    list_for_each_safe(st_head(table), ptr, next, olist) {
+	/* list_del is not needed */
+	st_free_entry(ptr);
     }
     table->num_entries = 0;
-    table->head = 0;
-    table->tail = 0;
+    MEMZERO(table->bins, st_table_entry*, table->num_bins);
+    list_head_init(st_head(table));
 }
 
 void
@@ -465,16 +464,7 @@ add_direct(st_table *table, st_data_t ke https://github.com/ruby/ruby/blob/trunk/st.c#L464
     }
 
     entry = new_entry(table, key, value, hash_val, bin_pos);
-
-    if (table->head != 0) {
-	entry->fore = 0;
-	(entry->back = table->tail)->fore = entry;
-	table->tail = entry;
-    }
-    else {
-	table->head = table->tail = entry;
-	entry->fore = entry->back = 0;
-    }
+    list_add_tail(st_head(table), &entry->olist);
     table->num_entries++;
 }
 
@@ -483,7 +473,7 @@ unpack_entries(register st_table *table) https://github.com/ruby/ruby/blob/trunk/st.c#L473
 {
     st_index_t i;
     st_packed_entry packed_bins[MAX_PACKED_HASH];
-    register st_table_entry *entry, *preventry = 0, **chain;
+    register st_table_entry *entry;
     st_table tmp_table = *table;
 
     MEMCPY(packed_bins, PACKED_BINS(table), st_packed_entry, MAX_PACKED_HASH);
@@ -495,22 +485,24 @@ unpack_entries(register st_table *table) https://github.com/ruby/ruby/blob/trunk/st.c#L485
     tmp_table.bins = st_realloc_bins(tmp_table.bins, ST_DEFAULT_INIT_TABLE_SIZE, tmp_table.num_bins);
     tmp_table.num_bins = ST_DEFAULT_INIT_TABLE_SIZE;
 #endif
+
+    /*
+     * order is important here, we need to keep the original table
+     * walkable during GC (GC may be triggered by new_entry call)
+     */
     i = 0;
-    chain = &tmp_table.head;
+    list_head_init(st_head(&tmp_table));
     do {
 	st_data_t key = packed_bins[i].key;
 	st_data_t val = packed_bins[i].val;
 	st_index_t hash = packed_bins[i].hash;
 	entry = new_entry(&tmp_table, key, val, hash,
 			  hash_pos(hash, ST_DEFAULT_INIT_TABLE_SIZE));
-	*chain = entry;
-	entry->back = preventry;
-	preventry = entry;
-	chain = &entry->fore;
+	list_add_tail(st_head(&tmp_table), &entry->olist);
     } while (++i < MAX_PACKED_HASH);
-    *chain = NULL;
-    tmp_table.tail = entry;
     *table = tmp_table;
+    list_head_init(st_head(table));
+    list_append_list(st_head(table), st_head(&tmp_table));
 }
 
 static void
@@ -620,12 +612,10 @@ rehash(register st_table *table) https://github.com/ruby/ruby/blob/trunk/st.c#L612
     table->num_bins = new_num_bins;
     table->bins = new_bins;
 
-    if ((ptr = table->head) != 0) {
-	do {
-	    hash_val = hash_pos(ptr->hash, new_num_bins);
-	    ptr->next = new_bins[hash_val];
-	    new_bins[hash_val] = ptr;
-	} while ((ptr = ptr->fore) != 0);
+    list_for_each(st_head(table), ptr, olist) {
+	hash_val = hash_pos(ptr->hash, new_num_bins);
+	ptr->next = new_bins[hash_val];
+	new_bins[hash_val] = ptr;
     }
 }
 
@@ -633,9 +623,8 @@ st_table* https://github.com/ruby/ruby/blob/trunk/st.c#L623
 st_copy(st_table *old_table)
 {
     st_table *new_table;
-    st_table_entry *ptr, *entry, *prev, **tailp;
+    st_table_entry *ptr, *entry;
     st_index_t num_bins = old_table->num_bins;
-    st_index_t hash_val;
 
     new_table = st_alloc_table();
     if (new_table == 0) {
@@ -655,24 +644,12 @@ st_copy(st_table *old_table) https://github.com/ruby/ruby/blob/trunk/st.c#L644
         return new_table;
     }
 
-    if ((ptr = old_table->head) != 0) {
-	prev = 0;
-	tailp = &new_table->head;
-	do {
-	    entry = st_alloc_entry();
-	    if (entry == 0) {
-		st_free_table(new_table);
-		return 0;
-	    }
-	    *entry = *ptr;
-	    hash_val = hash_pos(entry->hash, num_bins);
-	    entry->next = new_table->bins[hash_val];
-	    new_table->bins[hash_val] = entry;
-	    entry->back = prev;
-	    *tailp = prev = entry;
-	    tailp = &entry->fore;
-	} while ((ptr = ptr->fore) != 0);
-	new_table->tail = prev;
+    list_head_init(st_head(new_table));
+
+    list_for_each(st_head(old_table), ptr, olist) {
+	entry = new_entry(new_table, ptr->key, ptr->record, ptr->hash,
+			    hash_pos(ptr->hash, num_bins));
+	list_add_tail(st_head(new_table), &entry->olist);
     }
 
     return new_table;
@@ -681,17 +658,7 @@ st_copy(st_table *old_table) https://github.com/ruby/ruby/blob/trunk/st.c#L658
 static inline void
 remove_entry(st_table *table, st_table_entry *ptr)
 {
-    if (ptr->fore == 0 && ptr->back == 0) {
-	table->head = 0;
-	table->tail = 0;
-    }
-    else {
-	st_table_entry *fore = ptr->fore, *back = ptr->back;
-	if (fore) fore->back = back;
-	if (back) back->fore = fore;
-	if (ptr == table->head) table->head = fore;
-	if (ptr == table->tail) table->tail = back;
-    }
+    list_del(&ptr->olist);
     table->num_entries--;
 }
 
@@ -771,6 +738,7 @@ st_delete_safe(register st_table *table, https://github.com/ruby/ruby/blob/trunk/st.c#L738
 int
 st_shift(register st_table *table, register st_data_t *key, st_data_t *value)
 {
+    st_table_entry *old;
     st_table_entry **prev;
     register st_table_entry *ptr;
 
@@ -786,12 +754,13 @@ st_shift(register st_table *table, regis https://github.com/ruby/ruby/blob/trunk/st.c#L754
         return 1;
     }
 
-    prev = &table->bins[hash_pos(table->head->hash, table->num_bins)];
-    while ((ptr = *prev) != table->head) prev = &ptr->next;
+    old = list_pop(st_head(table), st_table_entry, olist);
+    table->num_entries--;
+    prev = &table->bins[hash_pos(old->hash, table->num_bins)];
+    while ((ptr = *prev) != old) prev = &ptr->next;
     *prev = ptr->next;
     if (value != 0) *value = ptr->record;
     *key = ptr->key;
-    remove_entry(table, ptr);
     st_free_entry(ptr);
     return 1;
 }
@@ -918,7 +887,8 @@ st_update(st_table *table, st_data_t key https://github.com/ruby/ruby/blob/trunk/st.c#L887
 int
 st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t never)
 {
-    st_table_entry *ptr, **last, *tmp;
+    st_table_entry *ptr, **last, *tmp, *next;
+    struct list_head *head;
     enum st_retval retval;
     st_index_t i;
 
@@ -935,8 +905,10 @@ st_foreach_check(st_table *table, int (* https://github.com/ruby/ruby/blob/trunk/st.c#L905
 		FIND_ENTRY(table, ptr, hash, i);
 		if (retval == ST_CHECK) {
 		    if (!ptr) goto deleted;
-		    goto unpacked_continue;
 		}
+		if (table->num_entries == 0) return 0;
+		head = st_head(table);
+		next = list_entry(ptr->olist.next, st_table_entry, olist);
 		goto unpacked;
 	    }
 	    switch (retval) {
@@ -961,14 +933,10 @@ st_foreach_check(st_table *table, int (* https://github.com/ruby/ruby/blob/trunk/st.c#L933
 	}
 	return 0;
     }
-    else {
-	ptr = table->head;
-    }
 
-    if (ptr != 0) {
-	do {
-	    if (ptr->key == never)
-		goto unpacked_continue;
+    head = st_head(table);
+    list_for_each_safe(head, ptr, next, olist) {
+	if (ptr->key != never) {
 	    i = hash_pos(ptr->hash, table->num_bins);
 	    retval = (*func)(ptr->key, ptr->record, arg, 0);
 	  unpacked:
@@ -984,8 +952,6 @@ st_foreach_check(st_table *table, int (* https://github.com/ruby/ruby/blob/trunk/st.c#L952
 		}
 		/* fall through */
 	      case ST_CONTINUE:
-	      unpacked_continue:
-		ptr = ptr->fore;
 		break;
 	      case ST_STOP:
 		return 0;
@@ -993,16 +959,15 @@ st_foreach_check(st_table *table, int (* https://github.com/ruby/ruby/blob/trunk/st.c#L959
 		last = &table->bins[hash_pos(ptr->hash, table->num_bins)];
 		for (; (tmp = *last) != 0; last = &tmp->next) {
 		    if (ptr == tmp) {
-			tmp = ptr->fore;
 			remove_entry(table, ptr);
 			ptr->key = ptr->record = never;
 			ptr->hash = 0;
-			ptr = tmp;
 			break;
 		    }
 		}
+		if (table->num_entries == 0) return 0;
 	    }
-	} while (ptr && table->head);
+	}
     }
     return 0;
 }
@@ -1010,8 +975,9 @@ st_foreach_check(st_table *table, int (* https://github.com/ruby/ruby/blob/trunk/st.c#L975
 int
 st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
 {
-    st_table_entry *ptr, **last, *tmp;
+    st_table_entry *ptr, **last, *tmp, *next;
     enum st_retval retval;
+    struct list_head *head;
     st_index_t i;
 
     if (table->entries_packed) {
@@ -1025,6 +991,8 @@ st_foreach(st_table *table, int (*func)( https://github.com/ruby/ruby/blob/trunk/st.c#L991
 	    if (!table->entries_packed) {
 		FIND_ENTRY(table, ptr, hash, i);
 		if (!ptr) return 0;
+		head = st_head(table);
+		next = list_entry(ptr->olist.next, st_table_entry, olist);
 		goto unpacked;
 	    }
 	    switch (retval) {
@@ -1041,36 +1009,30 @@ st_foreach(st_table *table, int (*func)( https://github.com/ruby/ruby/blob/trunk/st.c#L1009
 	}
 	return 0;
     }
-    else {
-	ptr = table->head;
-    }
 
-    if (ptr != 0) {
-	do {
-	    i = hash_pos(ptr->hash, table->num_bins);
-	    retval = (*func)(ptr->key, ptr->record, arg, 0);
-	  unpacked:
-	    switch (retval) {
-	      case ST_CONTINUE:
-		ptr = ptr->fore;
-		break;
-	      case ST_CHECK:
-	      case ST_STOP:
-		return 0;
-	      case ST_DELETE:
-		last = &table->bins[hash_pos(ptr->hash, table->num_bins)];
-		for (; (tmp = *last) != 0; last = &tmp->next) {
-		    if (ptr == tmp) {
-			tmp = ptr->fore;
-			*last = ptr->next;
-			remove_entry(table, ptr);
-			st_free_entry(ptr);
-			ptr = tmp;
-			break;
-		    }
+    head = st_head(table);
+    list_for_each_safe(head, ptr, next, olist) {
+	i = hash_pos(ptr->hash, table->num_bins);
+	retval = (*func)(ptr->key, ptr->record, arg, 0);
+      unpacked:
+	switch (retval) {
+	  case ST_CONTINUE:
+	    break;
+	  case ST_CHECK:
+	  case ST_STOP:
+	    return 0;
+	  case ST_DELETE:
+	    last = &table->bins[hash_pos(ptr->hash, table->num_bins)];
+	    for (; (tmp = *last) != 0; last = &tmp->next) {
+		if (ptr == tmp) {
+		    *last = ptr->next;
+		    remove_entry(table, ptr);
+		    st_free_entry(ptr);
+		    break;
 		}
 	    }
-	} while (ptr && table->head);
+	    if (table->num_entries == 0) return 0;
+	}
     }
     return 0;
 }
@@ -1092,9 +1054,11 @@ get_keys(st_table *table, st_data_t *key https://github.com/ruby/ruby/blob/trunk/st.c#L1054
 	}
     }
     else {
-	st_table_entry *ptr = table->head;
+	st_table_entry *ptr;
 	st_data_t *keys_end = keys + size;
-	for (; ptr && keys < keys_end; ptr = ptr->fore) {
+
+	list_for_each(st_head(table), ptr, olist) {
+	    if (keys >= keys_end) break;
 	    key = ptr->key;
 	    if (check && key == never) continue;
 	    *keys++ = key;
@@ -1133,9 +1097,11 @@ get_values(st_table *table, st_data_t *v https://github.com/ruby/ruby/blob/trunk/st.c#L1097
 	}
     }
     else {
-	st_table_entry *ptr = table->head;
+	st_table_entry *ptr;
 	st_data_t *values_end = values + size;
-	for (; ptr && values < values_end; ptr = ptr->fore) {
+
+	list_for_each(st_head(table), ptr, olist) {
+	    if (values >= values_end) break;
 	    key = ptr->key;
 	    if (check && key == never) continue;
 	    *values++ = ptr->record;
@@ -1161,7 +1127,8 @@ st_values_check(st_table *table, st_data https://github.com/ruby/ruby/blob/trunk/st.c#L1127
 int
 st_reverse_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t never)
 {
-    st_table_entry *ptr, **last, *tmp;
+    st_table_entry *ptr, **last, *tmp, *next;
+    struct list_head *head;
     enum st_retval retval;
     st_index_t i;
 
@@ -1179,8 +1146,10 @@ st_reverse_foreach_check(st_table *table https://github.com/ruby/ruby/blob/trunk/st.c#L1146
 		FIND_ENTRY(table, ptr, hash, i);
 		if (retval == ST_CHECK) {
 		    if (!ptr) goto deleted;
-		    goto unpacked_continue;
 		}
+		if (table->num_entries == 0) return 0;
+		head = st_head(table);
+		next = list_entry(ptr->olist.next, st_table_entry, olist);
 		goto unpacked;
 	    }
 	    switch (retval) {
@@ -1205,14 +1174,10 @@ st_reverse_foreach_check(st_table *table https://github.com/ruby/ruby/blob/trunk/st.c#L1174
 	}
 	return 0;
     }
-    else {
-	ptr = table->tail;
-    }
 
-    if (ptr != 0) {
-	do {
-	    if (ptr->key == never)
-		goto unpacked_continue;
+    head = st_head(table);
+    list_for_each_rev_safe(head, ptr, next, olist) {
+	if (ptr->key != never) {
 	    i = hash_pos(ptr->hash, table->num_bins);
 	    retval = (*func)(ptr->key, ptr->record, arg, 0);
 	  unpacked:
@@ -1228,8 +1193,6 @@ st_reverse_foreach_check(st_table *table https://github.com/ruby/ruby/blob/trunk/st.c#L1193
 		}
 		/* fall through */
 	      case ST_CONTINUE:
-	      unpacked_continue:
-		ptr = ptr->back;
 		break;
 	      case ST_STOP:
 		return 0;
@@ -1237,16 +1200,15 @@ st_reverse_foreach_check(st_table *table https://github.com/ruby/ruby/blob/trunk/st.c#L1200
 		last = &table->bins[hash_pos(ptr->hash, table->num_bins)];
 		for (; (tmp = *last) != 0; last = &tmp->next) {
 		    if (ptr == tmp) {
-			tmp = ptr->back;
 			remove_entry(table, ptr);
 			ptr->key = ptr->record = never;
 			ptr->hash = 0;
-			ptr = tmp;
 			break;
 		    }
 		}
+		if (table->num_entries == 0) return 0;
 	    }
-	} while (ptr && table->head);
+	}
     }
     return 0;
 }
@@ -1254,8 +1216,9 @@ st_reverse_foreach_check(st_table *table https://github.com/ruby/ruby/blob/trunk/st.c#L1216
 int
 st_reverse_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
 {
-    st_table_entry *ptr, **last, *tmp;
+    st_table_entry *ptr, **last, *tmp, *next;
     enum st_retval retval;
+    struct list_head *head;
     st_index_t i;
 
     if (table->entries_packed) {
@@ -1270,6 +1233,8 @@ st_reverse_foreach(st_table *table, int https://github.com/ruby/ruby/blob/trunk/st.c#L1233
 	    if (!table->entries_packed) {
 		FIND_ENTRY(table, ptr, hash, i);
 		if (!ptr) return 0;
+		head = st_head(table);
+		next = list_entry(ptr->olist.next, st_table_entry, olist);
 		goto unpacked;
 	    }
 	    switch (retval) {
@@ -1285,36 +1250,30 @@ st_reverse_foreach(st_table *table, int https://github.com/ruby/ruby/blob/trunk/st.c#L1250
 	}
 	return 0;
     }
-    else {
-	ptr = table->tail;
-    }
 
-    if (ptr != 0) {
-	do {
-	    i = hash_pos(ptr->hash, table->num_bins);
-	    retval = (*func)(ptr->key, ptr->record, arg, 0);
-	  unpacked:
-	    switch (retval) {
-	      case ST_CONTINUE:
-		ptr = ptr->back;
-		break;
-	      case ST_CHECK:
-	      case ST_STOP:
-		return 0;
-	      case ST_DELETE:
-		last = &table->bins[hash_pos(ptr->hash, table->num_bins)];
-		for (; (tmp = *last) != 0; last = &tmp->next) {
-		    if (ptr == tmp) {
-			tmp = ptr->back;
-			*last = ptr->next;
-			remove_entry(table, ptr);
-			st_free_entry(ptr);
-			ptr = tmp;
-			break;
-		    }
+    head = st_head(table);
+    list_for_each_rev_safe(head, ptr, next, olist) {
+	i = hash_pos(ptr->hash, table->num_bins);
+	retval = (*func)(ptr->key, ptr->record, arg, 0);
+      unpacked:
+	switch (retval) {
+	  case ST_CONTINUE:
+	    break;
+	  case ST_CHECK:
+	  case ST_STOP:
+	    return 0;
+	  case ST_DELETE:
+	    last = &table->bins[hash_pos(ptr->hash, table->num_bins)];
+	    for (; (tmp = *last) != 0; last = &tmp->next) {
+		if (ptr == tmp) {
+		    *last = ptr->next;
+		    remove_entry(table, ptr);
+		    st_free_entry(ptr);
+		    break;
 		}
 	    }
-	} while (ptr && table->head);
+	    if (table->num_entries == 0) return 0;
+	}
     }
     return 0;
 }

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

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