lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [09/15] git commit: refs/heads/cfish-string-prep1 - Introduce SStr_new_from_str, remove SStr_newf
Date Mon, 02 Sep 2013 19:16:40 GMT
Introduce SStr_new_from_str, remove SStr_newf


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

Branch: refs/heads/cfish-string-prep1
Commit: b38218a981ee4081dd45619924a123eb04d2ecd0
Parents: f8385c9
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Mon Sep 2 20:57:31 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Mon Sep 2 21:12:30 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/String.c   | 14 ++++++++------
 clownfish/runtime/core/Clownfish/String.cfh |  4 ++--
 core/Lucy/Index/ZombieKeyedHash.c           |  2 +-
 3 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/b38218a9/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index e2d58b2..92cc1c4 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -910,17 +910,19 @@ SStr_new(void *allocation) {
 }
 
 StackString*
-SStr_newf(void *allocation, size_t alloc_size, const char *pattern, ...) {
+SStr_new_from_str(void *allocation, size_t alloc_size, String *string) {
     StackString *self
         = (StackString*)VTable_Init_Obj(STACKSTRING, allocation);
     self->cap  = alloc_size - sizeof(StackString);
-    self->size = 0;
+    self->size = Str_Get_Size(string);
     self->ptr  = ((char*)allocation) + sizeof(StackString);
 
-    va_list args;
-    va_start(args, pattern);
-    SStr_VCatF(self, pattern, args);
-    va_end(args);
+    if (alloc_size < sizeof(StackString) + self->size + 1) {
+        THROW(ERR, "alloc_size of StackString too small");
+    }
+
+    memcpy(self->ptr, Str_Get_Ptr8(string), self->size);
+    self->ptr[self->size] = '\0';
 
     return self;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/b38218a9/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index 13cf2d8..8c4618f 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -377,10 +377,10 @@ class Clownfish::StackString cnick SStr
      * @param allocation A single block of memory which will be used for both
      * the StackString object and its buffer.
      * @param alloc_size The size of the allocation.
-     * @param pattern A format pattern.
+     * @param string String to be copied.
      */
     inert incremented StackString*
-    newf(void *allocation, size_t alloc_size, const char *pattern, ...);
+    new_from_str(void *allocation, size_t alloc_size, String *string);
 
     inert incremented StackString*
     wrap(void *allocation, const String *source);

http://git-wip-us.apache.org/repos/asf/lucy/blob/b38218a9/core/Lucy/Index/ZombieKeyedHash.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/ZombieKeyedHash.c b/core/Lucy/Index/ZombieKeyedHash.c
index b9ae141..2747888 100644
--- a/core/Lucy/Index/ZombieKeyedHash.c
+++ b/core/Lucy/Index/ZombieKeyedHash.c
@@ -49,7 +49,7 @@ ZKHash_Make_Key_IMP(ZombieKeyedHash *self, Obj *key, int32_t hash_sum) {
                 String *source = (String*)key;
                 size_t size = SStr_size() + Str_Get_Size(source) + 1;
                 void *allocation = MemPool_Grab(ivars->mem_pool, size);
-                retval = (Obj*)SStr_newf(allocation, size, "%o", source);
+                retval = (Obj*)SStr_new_from_str(allocation, size, source);
             }
             break;
         case FType_INT32: {


Mime
View raw message