You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/02/27 03:25:58 UTC
[lucy-commits] svn commit: r1074972 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Class.pm src/CFCClass.c src/CFCClass.h
Author: marvin
Date: Sun Feb 27 02:25:58 2011
New Revision: 1074972
URL: http://svn.apache.org/viewvc?rev=1074972&view=rev
Log:
Move some ancestry-related internals in CFCClass to C.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm
incubator/lucy/trunk/clownfish/src/CFCClass.c
incubator/lucy/trunk/clownfish/src/CFCClass.h
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1074972&r1=1074971&r2=1074972&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Sun Feb 27 02:25:58 2011
@@ -156,6 +156,12 @@ PPCODE:
CFCClass_bequeath_member_vars(self);
void
+_establish_ancestry(self)
+ CFCClass *self;
+PPCODE:
+ CFCClass_establish_ancestry(self);
+
+void
add_inert_var(self, var)
CFCClass *self;
CFCVariable *var;
@@ -198,6 +204,7 @@ ALIAS:
functions = 34
member_vars = 38
inert_vars = 40
+ tree_to_ladder = 42
PPCODE:
{
START_SET_OR_GET_SWITCH
@@ -336,6 +343,19 @@ PPCODE:
SvREFCNT_dec(av);
break;
}
+ case 42: {
+ AV *av = newAV();
+ CFCClass **ladder = CFCClass_tree_to_ladder(self);
+ size_t i;
+ for (i = 0; ladder[i] != NULL; i++) {
+ SV *val = newRV(CFCBase_get_perl_obj((CFCBase*)ladder[i]));
+ av_store(av, i, val);
+ }
+ FREEMEM(ladder);
+ retval = newRV((SV*)av);
+ SvREFCNT_dec(av);
+ break;
+ }
END_SET_OR_GET_SWITCH
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm?rev=1074972&r1=1074971&r2=1074972&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm Sun Feb 27 02:25:58 2011
@@ -194,17 +194,6 @@ sub grow_tree {
$self->_set_tree_grown(1);
}
-# Let the children know who their parent class is.
-sub _establish_ancestry {
- my $self = shift;
- for my $child ( @{ $self->children } ) {
- # This is a circular reference and thus a memory leak, but we don't
- # care, because we have to have everything in memory at once anyway.
- $child->set_parent($self);
- $child->_establish_ancestry;
- }
-}
-
# Create auto-generated methods. This must be called after member vars are
# passed down but before methods are passed down.
sub _generate_automethods {
@@ -250,15 +239,6 @@ sub _bequeath_methods {
}
}
-sub tree_to_ladder {
- my $self = shift;
- my @ladder = ($self);
- for my $child ( @{ $self->children } ) {
- push @ladder, @{ $child->tree_to_ladder };
- }
- return \@ladder;
-}
-
1;
__END__
Modified: incubator/lucy/trunk/clownfish/src/CFCClass.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCClass.c?rev=1074972&r1=1074971&r2=1074972&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCClass.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCClass.c Sun Feb 27 02:25:58 2011
@@ -291,6 +291,54 @@ CFCClass_bequeath_member_vars(CFCClass *
}
}
+// Let the children know who their parent class is.
+void
+CFCClass_establish_ancestry(CFCClass *self)
+{
+ size_t i;
+ for (i = 0; i < self->num_kids; i++) {
+ CFCClass *child = self->children[i];
+ // This is a circular reference and thus a memory leak, but we don't
+ // care, because we have to have everything in memory at once anyway.
+ CFCClass_set_parent(child, self);
+ CFCClass_establish_ancestry(child);
+ }
+}
+
+static size_t
+S_family_tree_size(CFCClass *self)
+{
+ size_t count = 1; // self
+ size_t i;
+ for (i = 0; i < self->num_kids; i++) {
+ count += S_family_tree_size(self->children[i]);
+ }
+ return count;
+}
+
+// Return value is valid only so long as object persists (elements are not
+// refcounted).
+CFCClass**
+CFCClass_tree_to_ladder(CFCClass *self)
+{
+ size_t ladder_len = S_family_tree_size(self);
+ CFCClass **ladder = MALLOCATE((ladder_len + 1) * sizeof(CFCClass*));
+ ladder[ladder_len] = NULL;
+ size_t step = 0;
+ ladder[step++] = self;
+ size_t i;
+ for (i = 0; i < self->num_kids; i++) {
+ CFCClass *child = self->children[i];
+ CFCClass **child_ladder = CFCClass_tree_to_ladder(child);
+ size_t j;
+ for (j = 0; child_ladder[j] != NULL; j++) {
+ ladder[step++] = child_ladder[j];
+ }
+ FREEMEM(child_ladder);
+ }
+ return ladder;
+}
+
CFCClass**
CFCClass_children(CFCClass *self)
{
Modified: incubator/lucy/trunk/clownfish/src/CFCClass.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCClass.h?rev=1074972&r1=1074971&r2=1074972&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCClass.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCClass.h Sun Feb 27 02:25:58 2011
@@ -61,6 +61,12 @@ CFCClass_function(CFCClass *self, const
void
CFCClass_bequeath_member_vars(CFCClass *self);
+void
+CFCClass_establish_ancestry(CFCClass *self);
+
+CFCClass**
+CFCClass_tree_to_ladder(CFCClass *self);
+
CFCClass**
CFCClass_children(CFCClass *self);