[svn:parrot] r49178 - trunk/src/pmc
luben at svn.parrot.org
luben at svn.parrot.org
Mon Sep 20 16:37:03 UTC 2010
Author: luben
Date: Mon Sep 20 16:37:03 2010
New Revision: 49178
URL: https://trac.parrot.org/parrot/changeset/49178
Log:
Fix HashIterator for NULL keys
Modified:
trunk/src/pmc/hashiterator.pmc
Modified: trunk/src/pmc/hashiterator.pmc
==============================================================================
--- trunk/src/pmc/hashiterator.pmc Mon Sep 20 15:57:25 2010 (r49177)
+++ trunk/src/pmc/hashiterator.pmc Mon Sep 20 16:37:03 2010 (r49178)
@@ -79,13 +79,32 @@
{
ASSERT_ARGS(advance_to_next)
Parrot_HashIterator_attributes * const attrs = PARROT_HASHITERATOR(self);
-
- while (attrs->elements > 0) {
- attrs->bucket = attrs->parrot_hash->buckets + attrs->pos++;
- if (attrs->bucket->key) {
- break;
+ if (attrs->parrot_hash->key_type == Hash_key_type_int
+ || attrs->parrot_hash->key_type == Hash_key_type_ptr
+ || attrs->parrot_hash->key_type == Hash_key_type_cstring){
+ /* indexed scan */
+ if (attrs->elements){
+ if (attrs->bucket)
+ attrs->bucket = attrs->bucket->next;
+ while (!attrs->bucket) {
+ /* If there is no more buckets */
+ if (attrs->pos == attrs->total_buckets)
+ break;
+ attrs->bucket = attrs->parrot_hash->index[attrs->pos++];
+ }
+ }
+ }
+ else{
+ /* linear scan */
+ if (!attrs->bucket)
+ attrs->bucket = attrs->parrot_hash->buckets;
+ while (attrs->elements > 0) {
+ attrs->bucket = attrs->parrot_hash->buckets + attrs->pos++;
+ if (attrs->bucket->key)
+ break;
}
}
+
--attrs->elements;
return;
}
@@ -116,8 +135,8 @@
attrs->pmc_hash = hash;
attrs->parrot_hash = (Hash*)VTABLE_get_pointer(INTERP, hash);
attrs->total_buckets = attrs->parrot_hash->mask + 1;
- attrs->bucket = attrs->parrot_hash->buckets;
attrs->elements = attrs->parrot_hash->entries;
+ attrs->bucket = NULL;
attrs->pos = 0;
PObj_custom_mark_SET(SELF);
@@ -163,8 +182,8 @@
if (value == ITERATE_FROM_START) {
/* Restart iterator */
- attrs->bucket = attrs->parrot_hash->buckets;
attrs->elements = attrs->parrot_hash->entries;
+ attrs->bucket = NULL;
attrs->pos = 0;
return;
}
More information about the parrot-commits
mailing list