[svn:parrot] r47821 - in trunk: include/parrot src src/pmc
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Fri Jun 25 03:16:57 UTC 2010
Author: chromatic
Date: Fri Jun 25 03:16:57 2010
New Revision: 47821
URL: https://trac.parrot.org/parrot/changeset/47821
Log:
[src] Optimized Class inspect_str hash cloning.
You may now perform shallow clones of hashes with the not-exported
parrot_hash_clone_pruneable() function; Class's inspect_str VTABLE now uses
this instead of cloning the hash manually. The function may need a better
name, and we may consider exporting it.
This optimization improves Rakudo startup by 3.557% and should improve all
object reflection similarly.
Modified:
trunk/include/parrot/hash.h
trunk/src/hash.c
trunk/src/pmc/class.pmc
Modified: trunk/include/parrot/hash.h
==============================================================================
--- trunk/include/parrot/hash.h Fri Jun 25 03:16:10 2010 (r47820)
+++ trunk/include/parrot/hash.h Fri Jun 25 03:16:57 2010 (r47821)
@@ -365,6 +365,15 @@
__attribute__nonnull__(4)
__attribute__nonnull__(5);
+void parrot_hash_clone_prunable(PARROT_INTERP,
+ ARGIN(const Hash *hash),
+ ARGOUT(Hash *dest),
+ int deep)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(*dest);
+
PARROT_WARN_UNUSED_RESULT
PARROT_PURE_FUNCTION
int PMC_compare(PARROT_INTERP, ARGIN(PMC *a), ARGIN(PMC *b))
@@ -505,6 +514,10 @@
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(compare) \
, PARROT_ASSERT_ARG(keyhash))
+#define ASSERT_ARGS_parrot_hash_clone_prunable __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(hash) \
+ , PARROT_ASSERT_ARG(dest))
#define ASSERT_ARGS_PMC_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(a) \
Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c Fri Jun 25 03:16:10 2010 (r47820)
+++ trunk/src/hash.c Fri Jun 25 03:16:57 2010 (r47821)
@@ -1451,6 +1451,14 @@
parrot_hash_clone(PARROT_INTERP, ARGIN(const Hash *hash), ARGOUT(Hash *dest))
{
ASSERT_ARGS(parrot_hash_clone)
+ parrot_hash_clone_prunable(interp, hash, dest, 1);
+}
+
+void
+parrot_hash_clone_prunable(PARROT_INTERP, ARGIN(const Hash *hash),
+ ARGOUT(Hash *dest), int deep)
+{
+ ASSERT_ARGS(parrot_hash_clone_prunable)
UINTVAL entries = hash->entries;
UINTVAL i;
@@ -1474,7 +1482,10 @@
if (PMC_IS_NULL((PMC *)b->value))
valtmp = (void *)PMCNULL;
else
- valtmp = (void *)VTABLE_clone(interp, (PMC*)b->value);
+ if (deep)
+ valtmp = (void *)VTABLE_clone(interp, (PMC*)b->value);
+ else
+ valtmp = b->value;
break;
default:
Modified: trunk/src/pmc/class.pmc
==============================================================================
--- trunk/src/pmc/class.pmc Fri Jun 25 03:16:10 2010 (r47820)
+++ trunk/src/pmc/class.pmc Fri Jun 25 03:16:57 2010 (r47821)
@@ -1112,13 +1112,11 @@
if (found->vtable->base_type == enum_class_Hash) {
/* for Hash return values, create and return a shallow
* clone because the VTABLE_clone does a deep clone */
- PMC * const hash = Parrot_pmc_new(INTERP, enum_class_Hash);
- PMC * const iter = VTABLE_get_iter(INTERP, found);
- while (VTABLE_get_bool(INTERP, iter)) {
- STRING * const key = VTABLE_shift_string(INTERP, iter);
- PMC * const value = VTABLE_get_pmc_keyed_str(INTERP, found, key);
- VTABLE_set_pmc_keyed_str(INTERP, hash, key, value);
- }
+ PMC * const hash = Parrot_pmc_new(INTERP, enum_class_Hash);
+ Hash *src = VTABLE_get_pointer(interp, found);
+ Hash *dest = VTABLE_get_pointer(interp, hash);
+
+ parrot_hash_clone_prunable(interp, src, dest, 0);
return hash;
}
More information about the parrot-commits
mailing list