On Thu, Jun 19, 2008 at 2:58 PM, chromatic <[EMAIL PROTECTED]> wrote: > On Thursday 19 June 2008 07:28:55 [EMAIL PROTECTED] wrote: > >> Log: >> [rakudo] Implement basic use of does operator for mixing in a role to an >> existing object at runtime. This was most neatly done with a dynop, so this >> check-in also adds a dynops file for Rakudo. make makefile will be required >> to build after this check-in. > >> Added: trunk/languages/perl6/src/ops/perl6.ops >> =========================================================================== >>=== --- (empty file) >> +++ trunk/languages/perl6/src/ops/perl6.ops Thu Jun 19 07:28:54 2008 >> @@ -0,0 +1,77 @@ >> +/* >> + * $Id:$ >> + * Copyright (C) 2008, The Perl Foundation. >> + */ >> + >> +#include "parrot/dynext.h" >> +#include "../../../../src/pmc/pmc_object.h" >> +VERSION = PARROT_VERSION; >> + >> +/* */ >> +inline op rebless_subclass(in PMC, in PMC) :base_core { >> + PMC *current_class; >> + PMC *parent_list; >> + PMC *value; >> + int i, num_parents, in_parents, new_attribs; >> + >> + /* First verify that the object's class is a superclass of the one >> we're + * to re-bless it into. While we're at it, count the number of >> attributes + * the current class has that the parent class does not. */ >> + current_class = VTABLE_get_class(interp, $1); >> + parent_list = VTABLE_inspect_str(interp, $2, >> string_from_literal(interp, "all_parents")); >> + num_parents = VTABLE_elements(interp, parent_list); >> + in_parents = 0; >> + new_attribs = 0; > > The initializations and declarations can go on the same lines. > > I'd like to replace all of the string_from_literal with const_string. While > the former calculates the string length at compile time (and saves a very > short strlen call at runtime), const_string uses a cache of constant string > headers, trading a lookup cost to retrieve or store a singletone string > header for not allocating a new non-constant string header on each > invocation. > > We'll already have "Mutable" and "attributes" in the cache, so this is > effectively a free optimization. > > -- c >
Does this cache work with dynops, dynpmcs, etc?? -- Will "Coke" Coleda