[svn:parrot] r48612 - in trunk: include/parrot src src/call
nwellnhof at svn.parrot.org
nwellnhof at svn.parrot.org
Mon Aug 23 13:21:43 UTC 2010
Author: nwellnhof
Date: Mon Aug 23 13:21:42 2010
New Revision: 48612
URL: https://trac.parrot.org/parrot/changeset/48612
Log:
Use hash iteration macro in dissect_aggregate_arg
This was the only user of parrot_hash_get_idx, so it can go away, too.
Modified:
trunk/include/parrot/hash.h
trunk/src/call/args.c
trunk/src/hash.c
Modified: trunk/include/parrot/hash.h
==============================================================================
--- trunk/include/parrot/hash.h Mon Aug 23 08:35:34 2010 (r48611)
+++ trunk/include/parrot/hash.h Mon Aug 23 13:21:42 2010 (r48612)
@@ -21,7 +21,6 @@
/* A BucketIndex is an index into the pool of available buckets. */
typedef UINTVAL BucketIndex;
-#define INITBucketIndex ((BucketIndex)-2)
#define N_BUCKETS(n) ((n))
#define HASH_ALLOC_SIZE(n) (N_BUCKETS(n) * sizeof (HashBucket) + \
@@ -191,17 +190,6 @@
__attribute__nonnull__(2);
PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-void * parrot_hash_get_idx(PARROT_INTERP,
- ARGIN(const Hash *hash),
- ARGMOD(PMC *key))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- FUNC_MODIFIES(*key);
-
-PARROT_EXPORT
PARROT_IGNORABLE_RESULT
PARROT_CANNOT_RETURN_NULL
HashBucket* parrot_hash_put(PARROT_INTERP,
@@ -469,10 +457,6 @@
#define ASSERT_ARGS_parrot_hash_get_bucket __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(hash))
-#define ASSERT_ARGS_parrot_hash_get_idx __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(hash) \
- , PARROT_ASSERT_ARG(key))
#define ASSERT_ARGS_parrot_hash_put __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(hash))
Modified: trunk/src/call/args.c
==============================================================================
--- trunk/src/call/args.c Mon Aug 23 08:35:34 2010 (r48611)
+++ trunk/src/call/args.c Mon Aug 23 13:21:42 2010 (r48612)
@@ -488,22 +488,13 @@
}
}
else if (VTABLE_does(interp, aggregate, CONST_STRING(interp, "hash"))) {
- const INTVAL elements = VTABLE_elements(interp, aggregate);
- INTVAL index;
- PMC * const key = Parrot_pmc_new(interp, enum_class_Key);
- VTABLE_set_integer_native(interp, key, 0);
- SETATTR_Key_next_key(interp, key, (PMC *)INITBucketIndex);
-
- /* Low-level hash iteration. */
- for (index = 0; index < elements; ++index) {
- if (!PMC_IS_NULL(key)) {
- STRING * const name = (STRING *)parrot_hash_get_idx(interp,
- (Hash *)VTABLE_get_pointer(interp, aggregate), key);
- PARROT_ASSERT(name);
- VTABLE_set_pmc_keyed_str(interp, call_object, name,
- VTABLE_get_pmc_keyed_str(interp, aggregate, name));
- }
- }
+ Hash *hash = (Hash *)VTABLE_get_pointer(interp, aggregate);
+
+ parrot_hash_iterate(hash,
+ VTABLE_set_pmc_keyed_str(interp, call_object,
+ (STRING *)_bucket->key,
+ hash_value_to_pmc(interp, hash, _bucket->value));
+ )
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c Mon Aug 23 08:35:34 2010 (r48611)
+++ trunk/src/hash.c Mon Aug 23 13:21:42 2010 (r48612)
@@ -1144,72 +1144,6 @@
/*
-=item C<void * parrot_hash_get_idx(PARROT_INTERP, const Hash *hash, PMC *key)>
-
-Finds the next index into the hash's internal storage for the given Key. Used
-by iterators. Ugly.
-
-=cut
-
-*/
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-void *
-parrot_hash_get_idx(PARROT_INTERP, ARGIN(const Hash *hash), ARGMOD(PMC *key))
-{
- ASSERT_ARGS(parrot_hash_get_idx)
- HashBucket *b;
- void *res;
- INTVAL i = VTABLE_get_integer(interp, key);
- PMC *fake_bi;
- BucketIndex bi;
-
- /* idx directly in the bucket store, which is at negative
- * address from the data pointer */
- /* locate initial */
- const INTVAL size = (INTVAL)N_BUCKETS(hash->mask + 1);
-
- GETATTR_Key_next_key(interp, key, fake_bi);
- bi = (BucketIndex)fake_bi;
-
- if (bi == INITBucketIndex) {
- i = 0;
- SETATTR_Key_next_key(interp, key, NULL);
- }
- else if (i >= size || i < 0) {
- /* NOTE: These instances of SETATTR_Key_int_key can't be VTABLE
- * functions because of the "special" way hash iterators work. */
- SETATTR_Key_int_key(interp, key, -1);
- return NULL;
- }
-
- res = NULL;
-
- for (b = hash->buckets + i; i < size ; ++i, ++b) {
- /* XXX int keys may be zero - use different iterator */
- if (b->key) {
- if (!res)
- res = b->key;
-
- /* found next key - FIXME hash iter does auto next */
- else
- break;
- }
- }
-
- if (i >= size)
- i = -1;
-
- SETATTR_Key_int_key(interp, key, i);
-
- return res;
-}
-
-
-/*
-
=item C<HashBucket * parrot_hash_get_bucket(PARROT_INTERP, const Hash *hash,
const void *key)>
More information about the parrot-commits
mailing list