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 22:27:36 UTC

[lucy-commits] svn commit: r1076801 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/Hierarchy.pm src/CFCHierarchy.c src/CFCHierarchy.h

Author: marvin
Date: Thu Mar  3 21:27:36 2011
New Revision: 1076801

URL: http://svn.apache.org/viewvc?rev=1076801&view=rev
Log:
Move storage for "files" member in CFCHierarchy 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=1076801&r1=1076800&r2=1076801&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Thu Mar  3 21:27:36 2011
@@ -733,12 +733,29 @@ PPCODE:
     CFCHierarchy_add_tree(self, klass);
 
 void
+_add_file(self, file)
+    CFCHierarchy *self;
+    CFCFile *file;
+PPCODE:
+    CFCHierarchy_add_file(self, file);
+
+SV*
+_fetch_file(self, source_class)
+    CFCHierarchy *self;
+    const char *source_class;
+CODE:
+    CFCFile *file = CFCHierarchy_fetch_file(self, source_class);
+    RETVAL = S_cfcbase_to_perlref(file);
+OUTPUT: RETVAL
+
+void
 _set_or_get(self, ...)
     CFCHierarchy *self;
 ALIAS:
     get_source        = 2
     get_dest          = 4
     _trees            = 6
+    _files            = 8
 PPCODE:
 {
     START_SET_OR_GET_SWITCH
@@ -756,6 +773,10 @@ PPCODE:
             retval = S_array_of_cfcbase_to_av(
                 (CFCBase**)CFCHierarchy_trees(self));
             break;
+        case 8:
+            retval = S_array_of_cfcbase_to_av(
+                (CFCBase**)CFCHierarchy_files(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=1076801&r1=1076800&r2=1076801&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm Thu Mar  3 21:27:36 2011
@@ -29,7 +29,6 @@ use Clownfish::Parser;
 
 # Inside-out member vars.
 our %parser;
-our %files;
 
 our %new_PARAMS = (
     source => undef,
@@ -42,36 +41,18 @@ sub new {
     my $package = ref($either) || $either;
     my $self = $package->_new( @args{qw( source dest )} );
     $parser{$self} = Clownfish::Parser->new;
-    $files{$self}  = [];
     return $self;
 }
 
 sub DESTROY {
     my $self = shift;
     delete $parser{$self};
-    delete $files{$self};
     $self->_destroy;
 }
 
 # Accessors.
 sub _get_parser { $parser{ +shift } }
 
-sub _store_file {
-    my ( $self, $file ) = @_;
-    my $source_class = $file->get_source_class;
-    if ( $self->_fetch_file($source_class) ) {
-        confess("File for '$source_class' already registered");
-    }
-    push @{ $files{$self} }, $file;
-}
-
-sub _fetch_file {
-    my ( $self, $source_class ) = @_;
-    my ($file)
-        = grep { $_->get_source_class eq $source_class } @{ $files{$self} };
-    return $file;
-}
-
 # Return flattened hierarchies.
 sub ordered_classes {
     my $self = shift;
@@ -82,7 +63,7 @@ sub ordered_classes {
     return @all;
 }
 
-sub files { return @{ $files{ +shift } } }
+sub files {  @{ shift->_files } }
 
 # Slurp all Clownfish header files.
 # Arrange the class objects into inheritance trees.
@@ -127,7 +108,7 @@ sub _parse_cf_files {
         my $file = $self->_get_parser
             ->file( $content, 0, source_class => $source_class, );
         confess("parse error for $source_path") unless defined $file;
-        $self->_store_file($file);
+        $self->_add_file($file);
         
         for my $class ( @{ $file->classes } ) {
             my $class_name = $class->get_class_name;

Modified: incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.c?rev=1076801&r1=1076800&r2=1076801&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.c Thu Mar  3 21:27:36 2011
@@ -23,6 +23,7 @@
 #include "CFCBase.h"
 #include "CFCHierarchy.h"
 #include "CFCClass.h"
+#include "CFCFile.h"
 #include "CFCUtil.h"
 
 struct CFCHierarchy {
@@ -31,6 +32,8 @@ struct CFCHierarchy {
     char *dest;
     CFCClass **trees;
     size_t num_trees;
+    CFCFile **files;
+    size_t num_files;
 };
 
 CFCHierarchy*
@@ -51,6 +54,8 @@ CFCHierarchy_init(CFCHierarchy *self, co
     self->dest      = CFCUtil_strdup(dest);
     self->trees     = (CFCClass**)CALLOCATE(1, sizeof(CFCClass*));
     self->num_trees = 0;
+    self->files     = (CFCFile**)CALLOCATE(1, sizeof(CFCFile*));
+    self->num_files = 0;
     return self;
 }
 
@@ -61,7 +66,11 @@ CFCHierarchy_destroy(CFCHierarchy *self)
     for (i = 0; self->trees[i] != NULL; i++) {
         CFCBase_decref((CFCBase*)self->trees[i]);
     }
+    for (i = 0; self->files[i] != NULL; i++) {
+        CFCBase_decref((CFCBase*)self->files[i]);
+    }
     FREEMEM(self->trees);
+    FREEMEM(self->files);
     FREEMEM(self->source);
     FREEMEM(self->dest);
     CFCBase_destroy((CFCBase*)self);
@@ -93,6 +102,41 @@ CFCHierarchy_trees(CFCHierarchy *self)
     return self->trees;
 }
 
+CFCFile*
+CFCHierarchy_fetch_file(CFCHierarchy *self, const char *source_class)
+{
+    size_t i;
+    for (i = 0; self->files[i] != NULL; i++) {
+        const char *existing = CFCFile_get_source_class(self->files[i]);
+        if (strcmp(source_class, existing) == 0) {
+            return self->files[i];
+        }
+    }
+    return NULL;
+}
+
+void
+CFCHierarchy_add_file(CFCHierarchy *self, CFCFile *file)
+{
+    CFCUTIL_NULL_CHECK(file);
+    const char *source_class = CFCFile_get_source_class(file);
+    if (CFCHierarchy_fetch_file(self, source_class)) {
+        Util_die("File for source class %s already registered", source_class);
+    }
+    self->num_files++;
+    size_t size = (self->num_files + 1) * sizeof(CFCFile*);
+    self->files = (CFCFile**)REALLOCATE(self->files, size);
+    self->files[self->num_files - 1] 
+        = (CFCFile*)CFCBase_incref((CFCBase*)file);
+    self->files[self->num_files] = NULL;
+}
+
+struct CFCFile**
+CFCHierarchy_files(CFCHierarchy *self)
+{
+    return self->files;
+}
+
 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=1076801&r1=1076800&r2=1076801&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.h Thu Mar  3 21:27:36 2011
@@ -23,6 +23,7 @@ extern "C" {
 
 typedef struct CFCHierarchy CFCHierarchy;
 struct CFCClass;
+struct CFCFile;
 
 CFCHierarchy*
 CFCHierarchy_new(const char *source, const char *dest);
@@ -39,6 +40,15 @@ CFCHierarchy_add_tree(CFCHierarchy *self
 struct CFCClass**
 CFCHierarchy_trees(CFCHierarchy *self);
 
+struct CFCFile*
+CFCHierarchy_fetch_file(CFCHierarchy *self, const char *source_class);
+
+void
+CFCHierarchy_add_file(CFCHierarchy *self, struct CFCFile *file);
+
+struct CFCFile**
+CFCHierarchy_files(CFCHierarchy *self);
+
 const char*
 CFCHierarchy_get_source(CFCHierarchy *self);