On Friday 03 October 2008 18:14:19 [EMAIL PROTECTED] wrote: > Log: > [pipp] implement clone, add, i_add and assign_pmc and enable associated > tests > > > Modified: trunk/languages/pipp/src/pmc/phparray.pmc > =========================================================================== >=== --- trunk/languages/pipp/src/pmc/phparray.pmc (original) > +++ trunk/languages/pipp/src/pmc/phparray.pmc Fri Oct 3 18:14:15 2008 > @@ -1416,6 +1416,147 @@ > > /* > > +=item C<PMC* clone()> > + > +Return a deep clone of this PHPArray. > + > +=cut > + > +*/ > + PMC *clone() { > + PMC *cloned_pmc, *cloned_value; > + STRING *cloned_key; > + PippHashTable *orig_ht, *cloned_ht; > + PippBucket *bkt; > + > + cloned_pmc = pmc_new(INTERP, PMC_type(SELF)); > + cloned_ht = (PippHashTable*) PMC_struct_val(cloned_pmc); > + orig_ht = (PippHashTable*) PMC_struct_val(SELF); > + pipp_hash_create(INTERP, orig_ht->capacity); > + > + for (bkt = orig_ht->tableHead; bkt != NULL; bkt = bkt->tableNext) > { + cloned_key = string_copy(INTERP, bkt->key); > + cloned_value = VTABLE_clone(INTERP, bkt->value); > + pipp_hash_put(INTERP, cloned_ht, cloned_key, cloned_value); > + } > + return cloned_pmc; > + }
You can declare and assign in the same statement, as long as you don't declare *after* any assignments, per C89. (Reducing the scope of variables reduces stack size used too, which probably isn't a concern here, but it's a nice benefit when we can get it.) -- c