lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] git commit: refs/heads/master - Use CFCUtil_sprintf() to simplify some code.
Date Fri, 02 Aug 2013 01:06:51 GMT
Updated Branches:
  refs/heads/master 120935d48 -> e10c9ccc5


Use CFCUtil_sprintf() to simplify some code.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/e10c9ccc
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/e10c9ccc
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/e10c9ccc

Branch: refs/heads/master
Commit: e10c9ccc526b8e49e266180401a821cd949c794c
Parents: 120935d
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Thu Aug 1 17:50:56 2013 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Thu Aug 1 17:50:56 2013 -0700

----------------------------------------------------------------------
 clownfish/compiler/src/CFCSymbol.c | 30 ++++++------------------------
 1 file changed, 6 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/e10c9ccc/clownfish/compiler/src/CFCSymbol.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCSymbol.c b/clownfish/compiler/src/CFCSymbol.c
index 60a364f..4d06677 100644
--- a/clownfish/compiler/src/CFCSymbol.c
+++ b/clownfish/compiler/src/CFCSymbol.c
@@ -169,30 +169,12 @@ CFCSymbol_init(CFCSymbol *self, struct CFCParcel *parcel,
     self->class_cnick = CFCUtil_strdup(real_cnick);
     self->micro_sym   = CFCUtil_strdup(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 = (char*)MALLOCATE(short_sym_len + 1);
-    if (self->class_cnick) {
-        memcpy((void*)self->short_sym, self->class_cnick, class_cnick_len);
-    }
-    self->short_sym[class_cnick_len] = '_';
-    memcpy(&self->short_sym[class_cnick_len + 1],
-           self->micro_sym, strlen(micro_sym));
-    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 = (char*)MALLOCATE(full_sym_len + 1);
-    memcpy(self->full_sym, prefix, prefix_len);
-    memcpy(&self->full_sym[prefix_len], self->short_sym, short_sym_len);
-    self->full_sym[full_sym_len] = '\0';
+    // Derive short_sym and full_sym.
+    char *cnick = self->class_cnick ? self->class_cnick : "";
+    self->short_sym = CFCUtil_sprintf("%s_%s", cnick, micro_sym);
+    self->full_sym
+        = CFCUtil_sprintf("%s%s", CFCParcel_get_prefix(self->parcel),
+                          self->short_sym);
 
     return self;
 }


Mime
View raw message