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/03 02:37:56 UTC

[lucy-commits] svn commit: r1066718 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/Parcel.pm src/CFCParcel.c src/CFCParcel.h

Author: marvin
Date: Thu Feb  3 01:37:56 2011
New Revision: 1066718

URL: http://svn.apache.org/viewvc?rev=1066718&view=rev
Log:
Port default_parcel() and equals() from Clownfish::Parcel to C.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm
    incubator/lucy/trunk/clownfish/src/CFCParcel.c
    incubator/lucy/trunk/clownfish/src/CFCParcel.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1066718&r1=1066717&r2=1066718&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Thu Feb  3 01:37:56 2011
@@ -180,6 +180,27 @@ DESTROY(self)
 PPCODE:
     CFCParcel_destroy(self);
 
+int
+equals(self, other)
+    CFCParcel *self;
+    CFCParcel *other;
+CODE:
+    RETVAL = CFCParcel_equals(self, other);
+OUTPUT: RETVAL
+
+SV*
+default_parcel(...)
+CODE:
+    static SV *default_parcel_sv = NULL;
+    if (default_parcel_sv == NULL) {
+        // This leaks, but that's OK.
+        CFCParcel *default_parcel = CFCParcel_default_parcel();
+        default_parcel_sv = newSV(0);
+        sv_setref_pv(default_parcel_sv, "Clownfish::Parcel", (void*)default_parcel);
+    }
+    RETVAL = newSVsv(default_parcel_sv);
+OUTPUT: RETVAL
+
 void
 _set_or_get(self, ...)
     CFCParcel *self;

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm?rev=1066718&r1=1066717&r2=1066718&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm Thu Feb  3 01:37:56 2011
@@ -29,21 +29,13 @@ our %singleton_PARAMS = (
     cnick => undef,
 );
 
-# Create the default parcel.
-our $default_parcel = __PACKAGE__->singleton(
-    name  => 'DEFAULT',
-    cnick => '',
-);
-
-sub default_parcel {$default_parcel}
-
 sub singleton {
     my ( $either, %args ) = @_;
     verify_args( \%singleton_PARAMS, %args ) or confess $@;
     my ( $name, $cnick ) = @args{qw( name cnick )};
 
     # Return the default parcel for either a blank name or an undefined name.
-    return $default_parcel unless $name;
+    return __PACKAGE__->default_parcel unless $name;
 
     # Return an existing singleton if the parcel has already been registered.
     my $existing = $parcels{$name};
@@ -64,13 +56,6 @@ sub singleton {
     return $self;
 }
 
-sub equals {
-    my ( $self, $other ) = @_;
-    return 0 unless $self->get_name  eq $other->get_name;
-    return 0 unless $self->get_cnick eq $other->get_cnick;
-    return 1;
-}
-
 1;
 
 __END__

Modified: incubator/lucy/trunk/clownfish/src/CFCParcel.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCParcel.c?rev=1066718&r1=1066717&r2=1066718&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCParcel.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCParcel.c Thu Feb  3 01:37:56 2011
@@ -109,6 +109,24 @@ CFCParcel_destroy(CFCParcel *self)
     free(self);
 }
 
+static CFCParcel *default_parcel = NULL;
+
+CFCParcel*
+CFCParcel_default_parcel(void)
+{
+    if (default_parcel == NULL) {
+        default_parcel = CFCParcel_new("DEFAULT", "");
+    }
+    return default_parcel;
+}
+
+int
+CFCParcel_equals(CFCParcel *self, CFCParcel *other)
+{
+    if (strcmp(self->name, other->name)) { return false; }
+    if (strcmp(self->cnick, other->cnick)) { return false; }
+    return true;
+}
 
 const char*
 CFCParcel_get_name(CFCParcel *self)

Modified: incubator/lucy/trunk/clownfish/src/CFCParcel.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCParcel.h?rev=1066718&r1=1066717&r2=1066718&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCParcel.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCParcel.h Thu Feb  3 01:37:56 2011
@@ -25,6 +25,12 @@ CFCParcel_init(CFCParcel *self, const ch
 void
 CFCParcel_destroy(CFCParcel *self);
 
+CFCParcel*
+CFCParcel_default_parcel(void);
+
+int
+CFCParcel_equals(CFCParcel *self, CFCParcel *other);
+
 const char*
 CFCParcel_get_name(CFCParcel *self);