[svn:parrot] r48633 - in trunk: include/parrot src src/pmc
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Tue Aug 24 16:52:19 UTC 2010
Author: plobsing
Date: Tue Aug 24 16:52:18 2010
New Revision: 48633
URL: https://trac.parrot.org/parrot/changeset/48633
Log:
consolidate hash freeze/thaw in src/hash.c
Modified:
trunk/include/parrot/hash.h
trunk/src/hash.c
trunk/src/pmc/hash.pmc
Modified: trunk/include/parrot/hash.h
==============================================================================
--- trunk/include/parrot/hash.h Tue Aug 24 16:33:45 2010 (r48632)
+++ trunk/include/parrot/hash.h Tue Aug 24 16:52:18 2010 (r48633)
@@ -410,11 +410,12 @@
__attribute__nonnull__(3)
FUNC_MODIFIES(*info);
-void Parrot_hash_thaw(PARROT_INTERP, ARGMOD(Hash *hash), ARGMOD(PMC *info))
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+PARROT_MALLOC
+Hash * Parrot_hash_thaw(PARROT_INTERP, ARGMOD(PMC *info))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
- __attribute__nonnull__(3)
- FUNC_MODIFIES(*hash)
FUNC_MODIFIES(*info);
PARROT_WARN_UNUSED_RESULT
@@ -559,7 +560,6 @@
, PARROT_ASSERT_ARG(info))
#define ASSERT_ARGS_Parrot_hash_thaw __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(hash) \
, PARROT_ASSERT_ARG(info))
#define ASSERT_ARGS_PMC_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c Tue Aug 24 16:33:45 2010 (r48632)
+++ trunk/src/hash.c Tue Aug 24 16:52:18 2010 (r48633)
@@ -491,7 +491,7 @@
/*
-=item C<void Parrot_hash_thaw(PARROT_INTERP, Hash *hash, PMC *info)>
+=item C<Hash * Parrot_hash_thaw(PARROT_INTERP, PMC *info)>
Visits the contents of a hash during freeze/thaw.
@@ -501,17 +501,46 @@
*/
-void
-Parrot_hash_thaw(PARROT_INTERP, ARGMOD(Hash *hash), ARGMOD(PMC *info))
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+PARROT_MALLOC
+Hash *
+Parrot_hash_thaw(PARROT_INTERP, ARGMOD(PMC *info))
{
ASSERT_ARGS(Parrot_hash_thaw)
- const size_t num_entries = (size_t) hash->entries;
- const Hash_key_type key_type = hash->key_type;
- const PARROT_DATA_TYPE entry_type = hash->entry_type;
- size_t entry_index;
+ const size_t num_entries = VTABLE_shift_integer(interp, info);
+ const Hash_key_type key_type = VTABLE_shift_integer(interp, info);
+ const PARROT_DATA_TYPE entry_type = VTABLE_shift_integer(interp, info);
+ size_t entry_index;
+ Hash *hash;
+
+ {
+ hash_comp_fn cmp_fn;
+ hash_hash_key_fn key_fn;
- hash->entries = 0;
+ switch (key_type) {
+ case Hash_key_type_int:
+ key_fn = (hash_hash_key_fn)key_hash_int;
+ cmp_fn = (hash_comp_fn)int_compare;
+ break;
+ case Hash_key_type_STRING:
+ key_fn = (hash_hash_key_fn)key_hash_STRING;
+ cmp_fn = (hash_comp_fn)STRING_compare;
+ break;
+ case Hash_key_type_PMC:
+ key_fn = (hash_hash_key_fn)key_hash_PMC;
+ cmp_fn = (hash_comp_fn)PMC_compare;
+ break;
+ default:
+ Parrot_ex_throw_from_c_args(interp, NULL, 1,
+ "unimplemented key type");
+ break;
+ }
+
+ hash = parrot_create_hash(interp, entry_type, key_type, cmp_fn, key_fn);
+
+ }
/* special case for great speed */
if (key_type == Hash_key_type_STRING
@@ -522,7 +551,7 @@
parrot_hash_put(interp, hash, (void *)key, (void *)i);
}
- return;
+ return hash;
}
for (entry_index = 0; entry_index < num_entries; ++entry_index) {
@@ -578,6 +607,8 @@
break;
}
}
+
+ return hash;
}
@@ -603,6 +634,10 @@
const size_t entries = hash->entries;
size_t i;
+ VTABLE_push_integer(interp, info, entries);
+ VTABLE_push_integer(interp, info, key_type);
+ VTABLE_push_integer(interp, info, entry_type);
+
parrot_hash_iterate(hash,
switch (key_type) {
case Hash_key_type_int:
Modified: trunk/src/pmc/hash.pmc
==============================================================================
--- trunk/src/pmc/hash.pmc Tue Aug 24 16:33:45 2010 (r48632)
+++ trunk/src/pmc/hash.pmc Tue Aug 24 16:52:18 2010 (r48633)
@@ -1163,14 +1163,8 @@
*/
VTABLE void freeze(PMC *info) {
- Hash * const hash = (Hash *)SELF.get_pointer();
-
SUPER(info);
- VTABLE_push_integer(INTERP, info, VTABLE_elements(INTERP, SELF));
- VTABLE_push_integer(INTERP, info, (INTVAL)hash->key_type);
- VTABLE_push_integer(INTERP, info, hash->entry_type);
-
- Parrot_hash_freeze(INTERP, hash, info);
+ Parrot_hash_freeze(INTERP, SELF.get_pointer(), info);
}
/*
@@ -1185,49 +1179,7 @@
VTABLE void thaw(PMC *info) {
SUPER(info);
-
- {
- const INTVAL elems = VTABLE_shift_integer(INTERP, info);
- const INTVAL k_type = VTABLE_shift_integer(INTERP, info);
- const INTVAL v_type = VTABLE_shift_integer(INTERP, info);
- Hash *hash;
-
- if (k_type != Hash_key_type_STRING || v_type != enum_hash_pmc) {
- hash_comp_fn cmp_fn;
- hash_hash_key_fn key_fn;
-
- switch (k_type) {
- case Hash_key_type_int:
- key_fn = (hash_hash_key_fn)key_hash_int;
- cmp_fn = (hash_comp_fn)int_compare;
- break;
- case Hash_key_type_STRING:
- key_fn = (hash_hash_key_fn)key_hash_STRING;
- cmp_fn = (hash_comp_fn)STRING_compare;
- break;
- case Hash_key_type_PMC:
- key_fn = (hash_hash_key_fn)key_hash_PMC;
- cmp_fn = (hash_comp_fn)PMC_compare;
- break;
- default:
- Parrot_ex_throw_from_c_args(INTERP, NULL, 1,
- "unimplemented key type");
- break;
- }
-
- SELF.set_pointer(parrot_create_hash(INTERP, (PARROT_DATA_TYPE)v_type,
- (Hash_key_type)k_type, cmp_fn, key_fn));
- }
-
- hash = (Hash *)SELF.get_pointer();
-
- PARROT_ASSERT((INTVAL)hash->key_type == k_type);
- PARROT_ASSERT(hash->entry_type == v_type);
-
- hash->entries = elems;
-
- Parrot_hash_thaw(INTERP, hash, info);
- }
+ SELF.set_pointer(Parrot_hash_thaw(INTERP, info));
}
}
More information about the parrot-commits
mailing list