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 22:49:53 UTC

[lucy-commits] svn commit: r1066992 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/Symbol.pm src/CFCSymbol.c src/CFCSymbol.h

Author: marvin
Date: Thu Feb  3 21:49:52 2011
New Revision: 1066992

URL: http://svn.apache.org/viewvc?rev=1066992&view=rev
Log:
Port Clownfish::Symbol methods short_sym() and full_sym() to C.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Symbol.pm
    incubator/lucy/trunk/clownfish/src/CFCSymbol.c
    incubator/lucy/trunk/clownfish/src/CFCSymbol.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1066992&r1=1066991&r2=1066992&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Thu Feb  3 21:49:52 2011
@@ -282,6 +282,8 @@ ALIAS:
     private         = 20
     parcel          = 22
     local           = 24
+    short_sym       = 26
+    full_sym        = 28
 PPCODE:
 {
     START_SET_OR_GET_SWITCH
@@ -341,6 +343,16 @@ PPCODE:
         case 24:
             retval = newSViv(CFCSymbol_local(self));
             break;
+        case 26: {
+                const char *short_sym = CFCSymbol_short_sym(self);
+                retval = newSVpvn(short_sym, strlen(short_sym));
+            }
+            break;
+        case 28: {
+                const char *full_sym = CFCSymbol_full_sym(self);
+                retval = newSVpvn(full_sym, strlen(full_sym));
+            }
+            break;
     END_SET_OR_GET_SWITCH
 }
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Symbol.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Symbol.pm?rev=1066992&r1=1066991&r2=1066992&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Symbol.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Symbol.pm Thu Feb  3 21:49:52 2011
@@ -61,16 +61,6 @@ sub new {
         $micro_sym );
 }
 
-sub full_sym {
-    my $self   = shift;
-    return $self->get_prefix . $self->short_sym;
-}
-
-sub short_sym {
-    my $self = shift;
-    return $self->get_class_cnick . '_' . $self->micro_sym;
-}
-
 sub equals {
     my ( $self, $other ) = @_;
     return 0 unless a_isa_b( $other, __PACKAGE__ );

Modified: incubator/lucy/trunk/clownfish/src/CFCSymbol.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCSymbol.c?rev=1066992&r1=1066991&r2=1066992&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCSymbol.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCSymbol.c Thu Feb  3 21:49:52 2011
@@ -165,6 +165,31 @@ CFCSymbol_init(CFCSymbol *self, struct C
     }
     self->micro_sym = savepv(micro_sym);
 
+    // Derive short_sym.
+    size_t class_cnick_len = self->class_cnick 
+                           ? strlen(self->class_cnick) 
+                           : 0;
+    size_t short_sym_len = class_cnick_len
+                         + strlen("_") 
+                         + strlen(self->micro_sym);
+    self->short_sym = (const char*)malloc(short_sym_len + 1);
+    if (self->class_cnick) {
+        memcpy((void*)self->short_sym, self->class_cnick, class_cnick_len);
+    }
+    *((char*)&self->short_sym[class_cnick_len]) = '_';
+    memcpy((void*)&self->short_sym[class_cnick_len + 1], 
+        self->micro_sym, strlen(micro_sym));
+    *((char*)&self->short_sym[short_sym_len]) = '\0';
+
+    // Derive full_sym;
+    const char *prefix = CFCParcel_get_prefix(self->parcel);
+    size_t prefix_len = strlen(prefix);
+    size_t full_sym_len = prefix_len + short_sym_len;
+    self->full_sym = (const char*)malloc(full_sym_len + 1);
+    memcpy((void*)self->full_sym, prefix, prefix_len);
+    memcpy((void*)&self->full_sym[prefix_len], self->short_sym, short_sym_len);
+    *((char*)&self->full_sym[full_sym_len]) = '\0';
+
     return self;
 }
 
@@ -176,6 +201,8 @@ CFCSymbol_destroy(CFCSymbol *self)
     Safefree(self->class_name);
     Safefree(self->class_cnick);
     Safefree(self->micro_sym);
+    free((void*)self->short_sym);
+    free((void*)self->full_sym);
     free(self);
 }
 
@@ -203,7 +230,17 @@ CFCSymbol_local(CFCSymbol *self)
     return !strcmp(self->exposure, "local");
 }
 
+const char*
+CFCSymbol_full_sym(CFCSymbol *self)
+{
+    return self->full_sym;
+}
 
+const char*
+CFCSymbol_short_sym(CFCSymbol *self)
+{
+    return self->short_sym;
+}
 
 struct CFCParcel*
 CFCSymbol_get_parcel(CFCSymbol *self)

Modified: incubator/lucy/trunk/clownfish/src/CFCSymbol.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCSymbol.h?rev=1066992&r1=1066991&r2=1066992&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCSymbol.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCSymbol.h Thu Feb  3 21:49:52 2011
@@ -24,6 +24,8 @@ struct CFCSymbol {
     const char *class_name;
     const char *class_cnick;
     const char *micro_sym;
+    const char *short_sym;
+    const char *full_sym;
 };
 #endif
 
@@ -69,6 +71,12 @@ const char*
 CFCSymbol_micro_sym(CFCSymbol *self);
 
 const char*
+CFCSymbol_short_sym(CFCSymbol *self);
+
+const char*
+CFCSymbol_full_sym(CFCSymbol *self);
+
+const char*
 CFCSymbol_get_prefix(CFCSymbol *self);
 
 const char*