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/03/03 03:34:15 UTC
[lucy-commits] svn commit: r1076503 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Hierarchy.pm src/CFCHierarchy.c src/CFCHierarchy.h
Author: marvin
Date: Thu Mar 3 02:34:15 2011
New Revision: 1076503
URL: http://svn.apache.org/viewvc?rev=1076503&view=rev
Log:
Move storage of "trees" (classes hierarchies descending from a single parent
with inheritance fleshed out) to C.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
incubator/lucy/trunk/clownfish/src/CFCHierarchy.h
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1076503&r1=1076502&r2=1076503&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Thu Mar 3 02:34:15 2011
@@ -726,11 +726,19 @@ PPCODE:
CFCHierarchy_destroy(self);
void
+_add_tree(self, klass)
+ CFCHierarchy *self;
+ CFCClass *klass;
+PPCODE:
+ CFCHierarchy_add_tree(self, klass);
+
+void
_set_or_get(self, ...)
CFCHierarchy *self;
ALIAS:
get_source = 2
get_dest = 4
+ _trees = 6
PPCODE:
{
START_SET_OR_GET_SWITCH
@@ -744,6 +752,10 @@ PPCODE:
retval = newSVpv(value, strlen(value));
}
break;
+ case 6:
+ retval = S_array_of_cfcbase_to_av(
+ (CFCBase**)CFCHierarchy_trees(self));
+ break;
END_SET_OR_GET_SWITCH
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm?rev=1076503&r1=1076502&r2=1076503&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm Thu Mar 3 02:34:15 2011
@@ -29,7 +29,6 @@ use Clownfish::Parser;
# Inside-out member vars.
our %parser;
-our %trees;
our %files;
our %new_PARAMS = (
@@ -43,7 +42,6 @@ sub new {
my $package = ref($either) || $either;
my $self = $package->_new( @args{qw( source dest )} );
$parser{$self} = Clownfish::Parser->new;
- $trees{$self} = {};
$files{$self} = {};
return $self;
}
@@ -51,13 +49,11 @@ sub new {
sub DESTROY {
my $self = shift;
delete $parser{$self};
- delete $trees{$self};
delete $files{$self};
$self->_destroy;
}
# Accessors.
-sub _get_trees { $trees{ +shift } }
sub _get_files { $files{ +shift } }
sub _get_parser { $parser{ +shift } }
@@ -65,7 +61,7 @@ sub _get_parser { $parser{ +shift } }
sub ordered_classes {
my $self = shift;
my @all;
- for my $tree ( values %{ $self->_get_trees } ) {
+ for my $tree ( @{ $self->_trees } ) {
push @all, @{ $tree->tree_to_ladder };
}
return @all;
@@ -78,7 +74,7 @@ sub files { values %{ shift->_get_files
sub build {
my $self = shift;
$self->_parse_cf_files;
- $_->grow_tree for values %{ $self->_get_trees };
+ $_->grow_tree for @{ $self->_trees };
}
sub _parse_cf_files {
@@ -136,7 +132,7 @@ sub _parse_cf_files {
$classes{$parent_name}->add_child($class);
}
else {
- $self->_get_trees->{$class_name} = $class;
+ $self->_add_tree($class);
}
}
}
@@ -145,7 +141,7 @@ sub propagate_modified {
my ( $self, $modified ) = @_;
# Seed the recursive write.
my $somebody_is_modified;
- for my $tree ( values %{ $self->_get_trees } ) {
+ for my $tree ( @{ $self->_trees } ) {
next unless $self->_propagate_modified( $tree, $modified );
$somebody_is_modified = 1;
}
Modified: incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.c?rev=1076503&r1=1076502&r2=1076503&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.c Thu Mar 3 02:34:15 2011
@@ -22,12 +22,15 @@
#define CFC_NEED_BASE_STRUCT_DEF
#include "CFCBase.h"
#include "CFCHierarchy.h"
+#include "CFCClass.h"
#include "CFCUtil.h"
struct CFCHierarchy {
CFCBase base;
char *source;
char *dest;
+ CFCClass **trees;
+ size_t num_trees;
};
CFCHierarchy*
@@ -44,19 +47,52 @@ CFCHierarchy_init(CFCHierarchy *self, co
if (!source || !strlen(source) || !dest || !strlen(dest)) {
croak("Both 'source' and 'dest' are required");
}
- self->source = CFCUtil_strdup(source);
- self->dest = CFCUtil_strdup(dest);
+ self->source = CFCUtil_strdup(source);
+ self->dest = CFCUtil_strdup(dest);
+ self->trees = (CFCClass**)CALLOCATE(1, sizeof(CFCClass*));
+ self->num_trees = 0;
return self;
}
void
CFCHierarchy_destroy(CFCHierarchy *self)
{
+ size_t i;
+ for (i = 0; self->trees[i] != NULL; i++) {
+ CFCBase_decref((CFCBase*)self->trees[i]);
+ }
+ FREEMEM(self->trees);
FREEMEM(self->source);
FREEMEM(self->dest);
CFCBase_destroy((CFCBase*)self);
}
+void
+CFCHierarchy_add_tree(CFCHierarchy *self, CFCClass *klass)
+{
+ CFCUTIL_NULL_CHECK(klass);
+ const char *full_struct_sym = CFCClass_full_struct_sym(klass);
+ size_t i;
+ for (i = 0; self->trees[i] != NULL; i++) {
+ const char *existing = CFCClass_full_struct_sym(self->trees[i]);
+ if (strcmp(full_struct_sym, existing) == 0) {
+ Util_die("Tree '%s' alread added", full_struct_sym);
+ }
+ }
+ self->num_trees++;
+ size_t size = (self->num_trees + 1) * sizeof(CFCClass*);
+ self->trees = (CFCClass**)REALLOCATE(self->trees, size);
+ self->trees[self->num_trees - 1]
+ = (CFCClass*)CFCBase_incref((CFCBase*)klass);
+ self->trees[self->num_trees] = NULL;
+}
+
+CFCClass**
+CFCHierarchy_trees(CFCHierarchy *self)
+{
+ return self->trees;
+}
+
const char*
CFCHierarchy_get_source(CFCHierarchy *self)
{
Modified: incubator/lucy/trunk/clownfish/src/CFCHierarchy.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.h?rev=1076503&r1=1076502&r2=1076503&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.h Thu Mar 3 02:34:15 2011
@@ -22,6 +22,7 @@ extern "C" {
#endif
typedef struct CFCHierarchy CFCHierarchy;
+struct CFCClass;
CFCHierarchy*
CFCHierarchy_new(const char *source, const char *dest);
@@ -32,6 +33,12 @@ CFCHierarchy_init(CFCHierarchy *self, co
void
CFCHierarchy_destroy(CFCHierarchy *self);
+void
+CFCHierarchy_add_tree(CFCHierarchy *self, struct CFCClass *klass);
+
+struct CFCClass**
+CFCHierarchy_trees(CFCHierarchy *self);
+
const char*
CFCHierarchy_get_source(CFCHierarchy *self);