[svn:parrot] r38501 - trunk/src/pmc
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Wed May 6 06:02:25 UTC 2009
Author: chromatic
Date: Wed May 6 06:02:24 2009
New Revision: 38501
URL: https://trac.parrot.org/parrot/changeset/38501
Log:
[PMC] Made Class PMC throw exception on attempt to overwrite a method or vtable
entry which already exists only when overwriting said entity with something
other than itself. This speeds up Rakudo startup by 4%.
Modified:
trunk/src/pmc/class.pmc
Modified: trunk/src/pmc/class.pmc
==============================================================================
--- trunk/src/pmc/class.pmc Wed May 6 05:31:44 2009 (r38500)
+++ trunk/src/pmc/class.pmc Wed May 6 06:02:24 2009 (r38501)
@@ -706,14 +706,19 @@
*/
VTABLE void add_method(STRING *name, PMC *sub) {
Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);
+ PMC * const method =
+ VTABLE_get_pmc_keyed_str(interp, _class->methods, name);
/* If we have already added a method with this name... */
- if (VTABLE_exists_keyed_str(interp, _class->methods, name))
- /* RT #46095 Need to handle multi methods here. */
+ if (!PMC_IS_NULL(method)) {
+ if (method == sub)
+ return;
+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"A method named '%S' already exists in class '%S'. "
"It may have been supplied by a role.",
name, VTABLE_get_string(interp, SELF));
+ }
/* Enter it into the table. */
VTABLE_set_pmc_keyed_str(interp, _class->methods, name, sub);
@@ -749,17 +754,25 @@
*/
VTABLE void add_vtable_override(STRING *name, PMC *sub) {
Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);
+ PMC * const vtable =
+ VTABLE_get_pmc_keyed_str(interp, _class->vtable_overrides, name);
/* If we have already added a vtable override with this name... */
- if (VTABLE_exists_keyed_str(interp, _class->vtable_overrides, name))
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ if (!PMC_IS_NULL(vtable)) {
+ if (vtable == sub)
+ return;
+
+ Parrot_ex_throw_from_c_args(interp, NULL,
+ EXCEPTION_INVALID_OPERATION,
"A vtable override named '%S' already exists in class '%S'. "
"It may have been supplied by a role.",
name, VTABLE_get_string(interp, SELF));
+ }
/* Check that the name is actually valid as a vtable override */
if (Parrot_get_vtable_index(interp, name) == -1)
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_METHOD_NOT_FOUND,
+ Parrot_ex_throw_from_c_args(interp, NULL,
+ EXCEPTION_METHOD_NOT_FOUND,
"'%S' is not a valid vtable function name.", name);
/* Add it to vtable methods list. */
More information about the parrot-commits
mailing list