lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [09/50] [abbrv] git commit: refs/heads/master - Remove 'cap' field from String
Date Fri, 11 Oct 2013 13:31:47 GMT
Remove 'cap' field from String


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

Branch: refs/heads/master
Commit: 7c42ec4626ae61a9ae21faad67ead4029bd46c0f
Parents: 4a210d7
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Tue Sep 10 02:35:54 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Fri Oct 11 15:28:14 2013 +0200

----------------------------------------------------------------------
 c/src/Lucy/Index/DocReader.c                |  4 ++--
 clownfish/runtime/core/Clownfish/CharBuf.c  |  2 +-
 clownfish/runtime/core/Clownfish/String.c   | 21 ++++++---------------
 clownfish/runtime/core/Clownfish/String.cfh |  8 +++-----
 core/Lucy/Index/SortCache/TextSortCache.c   |  2 +-
 core/Lucy/Util/Freezer.c                    |  7 +++----
 core/Lucy/Util/Json.c                       |  2 +-
 7 files changed, 17 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/7c42ec46/c/src/Lucy/Index/DocReader.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Index/DocReader.c b/c/src/Lucy/Index/DocReader.c
index 5a62738..dc3619b 100644
--- a/c/src/Lucy/Index/DocReader.c
+++ b/c/src/Lucy/Index/DocReader.c
@@ -77,8 +77,8 @@ DefDocReader_Fetch_Doc_IMP(DefaultDocReader *self, int32_t doc_id) {
                     char *buf = (char*)MALLOCATE(value_len + 1);
                     InStream_Read_Bytes(dat_in, buf, value_len);
                     buf[value_len] = '\0'; 
-                    value = (Obj*)Str_new_steal_from_trusted_str(
-                                buf, value_len, value_len + 1);
+                    value
+                        = (Obj*)Str_new_steal_from_trusted_str(buf, value_len);
                     break;
                 }
             case FType_BLOB: {

http://git-wip-us.apache.org/repos/asf/lucy/blob/7c42ec46/clownfish/runtime/core/Clownfish/CharBuf.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/CharBuf.c b/clownfish/runtime/core/Clownfish/CharBuf.c
index 8b6de34..74919dd 100644
--- a/clownfish/runtime/core/Clownfish/CharBuf.c
+++ b/clownfish/runtime/core/Clownfish/CharBuf.c
@@ -304,7 +304,7 @@ CB_To_String_IMP(CharBuf *self) {
 String*
 CB_Yield_String_IMP(CharBuf *self) {
     String *retval
-        = Str_new_steal_from_trusted_str(self->ptr, self->size, self->cap);
+        = Str_new_steal_from_trusted_str(self->ptr, self->size);
     self->ptr  = NULL;
     self->size = 0;
     self->cap  = 0;

http://git-wip-us.apache.org/repos/asf/lucy/blob/7c42ec46/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index a5544e0..ecc5989 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -72,7 +72,6 @@ Str_init(String *self, size_t size) {
 
     // Assign.
     self->size = 0;
-    self->cap  = size + 1;
 
     return self;
 }
@@ -102,32 +101,30 @@ Str_init_from_trusted_utf8(String *self, const char *ptr, size_t size)
{
 
     // Assign.
     self->size      = size;
-    self->cap       = size + 1;
     self->ptr[size] = '\0'; // Null terminate.
 
     return self;
 }
 
 String*
-Str_new_steal_from_trusted_str(char *ptr, size_t size, size_t cap) {
+Str_new_steal_from_trusted_str(char *ptr, size_t size) {
     String *self = (String*)VTable_Make_Obj(STRING);
-    return Str_init_steal_trusted_str(self, ptr, size, cap);
+    return Str_init_steal_trusted_str(self, ptr, size);
 }
 
 String*
-Str_init_steal_trusted_str(String *self, char *ptr, size_t size, size_t cap) {
+Str_init_steal_trusted_str(String *self, char *ptr, size_t size) {
     self->ptr  = ptr;
     self->size = size;
-    self->cap  = cap;
     return self;
 }
 
 String*
-Str_new_steal_str(char *ptr, size_t size, size_t cap) {
+Str_new_steal_str(char *ptr, size_t size) {
     if (!StrHelp_utf8_valid(ptr, size)) {
         DIE_INVALID_UTF8(ptr, size);
     }
-    return Str_new_steal_from_trusted_str(ptr, size, cap);
+    return Str_new_steal_from_trusted_str(ptr, size);
 }
 
 String*
@@ -135,7 +132,6 @@ Str_new_from_char(uint32_t code_point) {
     const size_t MAX_UTF8_BYTES = 4;
     String *self = (String*)VTable_Make_Obj(STRING);
     self->ptr  = (char*)MALLOCATE(MAX_UTF8_BYTES + 1);
-    self->cap  = MAX_UTF8_BYTES + 1;
     self->size = StrHelp_encode_utf8_char(code_point, (uint8_t*)self->ptr);
     self->ptr[self->size] = '\0';
     return self;
@@ -313,8 +309,7 @@ Str_Cat_Trusted_UTF8_IMP(String *self, const char* ptr, size_t size) {
     memcpy(result_ptr + self->size, ptr, size);
     result_ptr[result_size] = '\0';
     String *result = (String*)VTable_Make_Obj(STRING);
-    return Str_init_steal_trusted_str(result, result_ptr, result_size,
-                                      result_size + 1);
+    return Str_init_steal_trusted_str(result, result_ptr, result_size);
 }
 
 bool
@@ -540,7 +535,6 @@ ViewCharBuf*
 ViewCB_init(ViewCharBuf *self, const char *utf8, size_t size) {
     self->ptr  = (char*)utf8;
     self->size = size;
-    self->cap  = 0;
     return self;
 }
 
@@ -558,7 +552,6 @@ SStr_new(void *allocation) {
     static char empty_string[] = "";
     StackString *self
         = (StackString*)VTable_Init_Obj(STACKSTRING, allocation);
-    self->cap  = 0;
     self->size = 0;
     self->ptr  = empty_string;
     return self;
@@ -568,7 +561,6 @@ StackString*
 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 = Str_Get_Size(string);
     self->ptr  = ((char*)allocation) + sizeof(StackString);
 
@@ -586,7 +578,6 @@ StackString*
 SStr_wrap_str(void *allocation, const char *ptr, size_t size) {
     StackString *self
         = (StackString*)VTable_Init_Obj(STACKSTRING, allocation);
-    self->cap  = 0;
     self->size = size;
     self->ptr  = (char*)ptr;
     return self;

http://git-wip-us.apache.org/repos/asf/lucy/blob/7c42ec46/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index 876657d..8f666ac 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -25,7 +25,6 @@ class Clownfish::String cnick Str
 
     char    *ptr;
     size_t   size;
-    size_t   cap;  /* allocated bytes, including terminating null */
 
     inert incremented String*
     new(size_t size);
@@ -55,20 +54,19 @@ class Clownfish::String cnick Str
      * passed-in string.  Check validity of supplied UTF-8.
      */
     inert incremented String*
-    new_steal_str(char *ptr, size_t size, size_t cap);
+    new_steal_str(char *ptr, size_t size);
 
     /** Return a pointer to a new String which assumes ownership of the
      * passed-in string.  Do not check validity of supplied UTF-8.
      */
     inert incremented String*
-    new_steal_from_trusted_str(char *ptr, size_t size, size_t cap);
+    new_steal_from_trusted_str(char *ptr, size_t size);
 
     /** Initialize the String using the passed-in string.  Do not check
      * validity of supplied UTF-8.
      */
     public inert String*
-    init_steal_trusted_str(decremented String *self, char *ptr,
-                           size_t size, size_t cap);
+    init_steal_trusted_str(decremented String *self, char *ptr, size_t size);
 
     /** Return a String which holds a single character.
      */

http://git-wip-us.apache.org/repos/asf/lucy/blob/7c42ec46/core/Lucy/Index/SortCache/TextSortCache.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortCache/TextSortCache.c b/core/Lucy/Index/SortCache/TextSortCache.c
index 97df2bb..afd5b50 100644
--- a/core/Lucy/Index/SortCache/TextSortCache.c
+++ b/core/Lucy/Index/SortCache/TextSortCache.c
@@ -115,7 +115,7 @@ TextSortCache_Value_IMP(TextSortCache *self, int32_t ord) {
         InStream_Seek(ivars->dat_in, offset);
         InStream_Read_Bytes(ivars->dat_in, ptr, len);
         ptr[len] = '\0';
-        return (Obj*)Str_new_steal_str(ptr, len, len + 1);
+        return (Obj*)Str_new_steal_str(ptr, len);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/7c42ec46/core/Lucy/Util/Freezer.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Freezer.c b/core/Lucy/Util/Freezer.c
index cdaeffc..e492962 100644
--- a/core/Lucy/Util/Freezer.c
+++ b/core/Lucy/Util/Freezer.c
@@ -216,14 +216,13 @@ Freezer_deserialize_string(String *string, InStream *instream) {
     if (size == SIZE_MAX) {
         THROW(ERR, "Can't deserialize SIZE_MAX bytes");
     }
-    size_t cap = Memory_oversize(size + 1, sizeof(char));
-    char *buf = MALLOCATE(cap);
+    char *buf = MALLOCATE(size + 1);
     InStream_Read_Bytes(instream, buf, size);
     buf[size] = '\0';
     if (!StrHelp_utf8_valid(buf, size)) {
         THROW(ERR, "Attempt to deserialize invalid UTF-8");
     }
-    return Str_init_steal_trusted_str(string, buf, size, cap);
+    return Str_init_steal_trusted_str(string, buf, size);
 }
 
 String*
@@ -339,7 +338,7 @@ Freezer_deserialize_hash(Hash *hash, InStream *instream) {
         char *key_buf = (char*)MALLOCATE(len + 1);
         InStream_Read_Bytes(instream, key_buf, len);
         key_buf[len] = '\0';
-        String *key = Str_new_steal_from_trusted_str(key_buf, len, len + 1);
+        String *key = Str_new_steal_from_trusted_str(key_buf, len);
         Hash_Store(hash, (Obj*)key, THAW(instream));
         DECREF(key);
     }

http://git-wip-us.apache.org/repos/asf/lucy/blob/7c42ec46/core/Lucy/Util/Json.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Json.c b/core/Lucy/Util/Json.c
index 61018d6..b5e7f57 100644
--- a/core/Lucy/Util/Json.c
+++ b/core/Lucy/Util/Json.c
@@ -653,7 +653,7 @@ S_unescape_text(char *const top, char *const end) {
         Err_set_error(Err_new(mess));
         return NULL;
     }
-    return Str_new_steal_from_trusted_str(target_buf, target_size, cap);
+    return Str_new_steal_from_trusted_str(target_buf, target_size);
 }
 
 static CFISH_INLINE bool


Mime
View raw message