lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [1/7] lucy-clownfish git commit: Remove obsolete CharBuf ctors and methods
Date Sun, 15 Nov 2015 11:45:20 GMT
Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 71ea0c573 -> cf29eb724


Remove obsolete CharBuf ctors and methods

Also change CB_Grow return type.


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

Branch: refs/heads/master
Commit: ad19eb8d8d8e5272365a5808ad09c34defd88a7e
Parents: 71ea0c5
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Thu Nov 12 14:47:14 2015 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Thu Nov 12 14:49:50 2015 +0100

----------------------------------------------------------------------
 runtime/core/Clownfish/CharBuf.c          | 100 ++-----------------------
 runtime/core/Clownfish/CharBuf.cfh        |  47 +-----------
 runtime/core/Clownfish/Err.c              |   3 +-
 runtime/core/Clownfish/Test/TestCharBuf.c |  79 ++-----------------
 4 files changed, 17 insertions(+), 212 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ad19eb8d/runtime/core/Clownfish/CharBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/CharBuf.c b/runtime/core/Clownfish/CharBuf.c
index 6e54910..bd388b8 100644
--- a/runtime/core/Clownfish/CharBuf.c
+++ b/runtime/core/Clownfish/CharBuf.c
@@ -68,60 +68,18 @@ CB_init(CharBuf *self, size_t size) {
     return self;
 }
 
-CharBuf*
-CB_new_from_str(String *string) {
-    return CB_new_from_trusted_utf8(string->ptr, string->size);
-}
-
-CharBuf*
-CB_new_from_utf8(const char *ptr, size_t size) {
-    if (!StrHelp_utf8_valid(ptr, size)) {
-        DIE_INVALID_UTF8(ptr, size);
-    }
-    return CB_new_from_trusted_utf8(ptr, size);
-}
-
-CharBuf*
-CB_new_from_trusted_utf8(const char *ptr, size_t size) {
-    CharBuf *self = (CharBuf*)Class_Make_Obj(CHARBUF);
-
-    // Derive.
-    self->ptr = (char*)MALLOCATE(size + 1);
-
-    // Copy.
-    memcpy(self->ptr, ptr, size);
-
-    // Assign.
-    self->size      = size;
-    self->cap       = size + 1;
-    self->ptr[size] = '\0'; // Null terminate.
-
-    return self;
-}
-
-CharBuf*
-CB_newf(const char *pattern, ...) {
-    CharBuf *self = CB_new(strlen(pattern));
-    va_list args;
-    va_start(args, pattern);
-    CB_VCatF(self, pattern, args);
-    va_end(args);
-    return self;
-}
-
 void
 CB_Destroy_IMP(CharBuf *self) {
     FREEMEM(self->ptr);
     SUPER_DESTROY(self, CHARBUF);
 }
 
-char*
+void
 CB_Grow_IMP(CharBuf *self, size_t size) {
     if (size >= self->cap) {
         self->cap = size + 1;
         self->ptr = (char*)REALLOCATE(self->ptr, self->cap);
     }
-    return self->ptr;
 }
 
 static void
@@ -318,44 +276,14 @@ CB_Cat_Char_IMP(CharBuf *self, int32_t code_point) {
 
 CharBuf*
 CB_Clone_IMP(CharBuf *self) {
-    return CB_new_from_trusted_utf8(self->ptr, self->size);
-}
+    size_t   size  = self->size;
+    CharBuf *clone = CB_new(size);
 
-static CFISH_INLINE void
-SI_mimic_utf8(CharBuf *self, const char* ptr, size_t size) {
-    if (size >= self->cap) { CB_Grow(self, size); }
-    memmove(self->ptr, ptr, size);
-    self->size = size;
-    self->ptr[size] = '\0';
-}
+    clone->size = size;
+    memcpy(clone->ptr, self->ptr, size);
+    clone->ptr[size] = '\0';
 
-void
-CB_Mimic_Utf8_IMP(CharBuf *self, const char* ptr, size_t size) {
-    if (!StrHelp_utf8_valid(ptr, size)) {
-        DIE_INVALID_UTF8(ptr, size);
-    }
-    SI_mimic_utf8(self, ptr, size);
-}
-
-void
-CB_Mimic_IMP(CharBuf *self, Obj *other) {
-    const char *ptr;
-    size_t size;
-    if (Obj_is_a(other, CHARBUF)) {
-        CharBuf *twin = (CharBuf*)other;
-        ptr  = twin->ptr;
-        size = twin->size;
-    }
-    else if (Obj_is_a(other, STRING)) {
-        String *twin = (String*)other;
-        ptr  = twin->ptr;
-        size = twin->size;
-    }
-    else {
-        THROW(ERR, "CharBuf can't mimic %o", Obj_get_class_name(other));
-        return; // unreachable
-    }
-    SI_mimic_utf8(self, ptr, size);
+    return clone;
 }
 
 static CFISH_INLINE void
@@ -393,23 +321,9 @@ CB_Clear_IMP(CharBuf *self) {
     self->size = 0;
 }
 
-void
-CB_Set_Size_IMP(CharBuf *self, size_t size) {
-    if (size >= self->cap) {
-        THROW(ERR, "Can't set size of CharBuf beyond capacity");
-        return; // unreachable
-    }
-    self->size = size;
-}
-
 size_t
 CB_Get_Size_IMP(CharBuf *self) {
     return self->size;
 }
 
-char*
-CB_Get_Ptr8_IMP(CharBuf *self) {
-    return self->ptr;
-}
-
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ad19eb8d/runtime/core/Clownfish/CharBuf.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/CharBuf.cfh b/runtime/core/Clownfish/CharBuf.cfh
index 0112ae8..7714443 100644
--- a/runtime/core/Clownfish/CharBuf.cfh
+++ b/runtime/core/Clownfish/CharBuf.cfh
@@ -33,38 +33,6 @@ final class Clownfish::CharBuf nickname CB
     inert CharBuf*
     init(CharBuf *self, size_t size);
 
-    /** Return a new CharBuf which holds a copy of the passed-in String.
-     */
-    inert incremented CharBuf*
-    new_from_str(String *string);
-
-    /** Return a new CharBuf which holds a copy of the passed-in string.
-     * Check for UTF-8 validity.
-     */
-    inert incremented CharBuf*
-    new_from_utf8(const char *utf8, size_t size);
-
-    /** Return a new CharBuf which holds a copy of the passed-in string.  No
-     * validity checking is performed.
-     */
-    inert incremented CharBuf*
-    new_from_trusted_utf8(const char *utf8, size_t size);
-
-    /** Return a pointer to a new CharBuf which contains formatted data
-     * expanded according to CB_VCatF.
-     *
-     * Note: a user-supplied `pattern` string is a security hole
-     * and must not be allowed.
-     */
-    inert incremented CharBuf*
-    newf(const char *pattern, ...);
-
-    public void
-    Mimic(CharBuf *self, Obj *other);
-
-    void
-    Mimic_Utf8(CharBuf *self, const char *ptr, size_t size);
-
     /** Concatenate the passed-in string onto the end of the CharBuf.
      */
     void
@@ -111,10 +79,8 @@ final class Clownfish::CharBuf nickname CB
     /** Assign more memory to the CharBuf, if it doesn't already have enough
      * room to hold a string of `size` bytes.  Cannot shrink the
      * allocation.
-     *
-     * @return a pointer to the raw buffer.
      */
-    char*
+    void
     Grow(CharBuf *self, size_t size);
 
     /** Clear the CharBuf.
@@ -122,22 +88,11 @@ final class Clownfish::CharBuf nickname CB
     void
     Clear(CharBuf *self);
 
-    /** Set the CharBuf's `size` attribute.
-     */
-    void
-    Set_Size(CharBuf *self, size_t size);
-
     /** Get the CharBuf's `size` attribute.
      */
     size_t
     Get_Size(CharBuf *self);
 
-    /** Return the internal backing array for the CharBuf if its internal
-     * encoding is UTF-8.  If it is not encoded as UTF-8 throw an exception.
-     */
-    char*
-    Get_Ptr8(CharBuf *self);
-
     public incremented CharBuf*
     Clone(CharBuf *self);
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ad19eb8d/runtime/core/Clownfish/Err.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Err.c b/runtime/core/Clownfish/Err.c
index 8463e0d..dd398e7 100644
--- a/runtime/core/Clownfish/Err.c
+++ b/runtime/core/Clownfish/Err.c
@@ -154,7 +154,8 @@ Err_Get_Mess_IMP(Err *self) {
 
 void
 Err_Add_Frame_IMP(Err *self, const char *file, int line, const char *func) {
-    CharBuf *buf = CB_new_from_str(self->mess);
+    CharBuf *buf = CB_new(0);
+    CB_Cat(buf, self->mess);
 
     if (!Str_Ends_With_Utf8(self->mess, "\n", 1)) {
         CB_Cat_Char(buf, '\n');

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ad19eb8d/runtime/core/Clownfish/Test/TestCharBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestCharBuf.c b/runtime/core/Clownfish/Test/TestCharBuf.c
index 5763e99..744c4f4 100644
--- a/runtime/core/Clownfish/Test/TestCharBuf.c
+++ b/runtime/core/Clownfish/Test/TestCharBuf.c
@@ -42,7 +42,9 @@ TestCB_new() {
 
 static CharBuf*
 S_get_cb(const char *string) {
-    return CB_new_from_utf8(string, strlen(string));
+    CharBuf *cb = CB_new(0);
+    CB_Cat_Utf8(cb, string, strlen(string));
+    return cb;
 }
 
 static String*
@@ -59,25 +61,6 @@ S_cb_equals(CharBuf *cb, String *other) {
 }
 
 static void
-test_new(TestBatchRunner *runner) {
-    {
-        String  *str = Str_newf("CharBuf from String");
-        CharBuf *cb  = CB_new_from_str(str);
-        TEST_TRUE(runner, S_cb_equals(cb, str), "CB_new_from_str");
-        DECREF(str);
-        DECREF(cb);
-    }
-
-    {
-        CharBuf *cb     = CB_newf("%i32 %s", 99, "Luftballons");
-        String  *wanted = Str_newf("99 Luftballons");
-        TEST_TRUE(runner, S_cb_equals(cb, wanted), "CB_newf");
-        DECREF(cb);
-        DECREF(wanted);
-    }
-}
-
-static void
 test_Cat(TestBatchRunner *runner) {
     String  *wanted = Str_newf("a%s", smiley);
     CharBuf *got    = S_get_cb("");
@@ -105,63 +88,17 @@ test_Cat(TestBatchRunner *runner) {
 }
 
 static void
-test_Mimic_and_Clone(TestBatchRunner *runner) {
+test_Clone(TestBatchRunner *runner) {
     String  *wanted    = S_get_str("foo");
     CharBuf *wanted_cb = S_get_cb("foo");
-    CharBuf *got       = S_get_cb("bar");
-
-    CB_Mimic(got, (Obj*)wanted);
-    TEST_TRUE(runner, S_cb_equals(got, wanted), "Mimic String");
-    DECREF(got);
-
-    got = S_get_cb("bar");
-    CB_Mimic(got, (Obj*)wanted_cb);
-    TEST_TRUE(runner, S_cb_equals(got, wanted), "Mimic CharBuf");
-    DECREF(got);
-
-    got = S_get_cb("bar");
-    CB_Mimic_Utf8(got, "foo", 3);
-    TEST_TRUE(runner, S_cb_equals(got, wanted), "Mimic_Utf8");
-    DECREF(got);
-
-    got = CB_Clone(wanted_cb);
+    CharBuf *got       = CB_Clone(wanted_cb);
     TEST_TRUE(runner, S_cb_equals(got, wanted), "Clone");
     DECREF(got);
-
     DECREF(wanted);
     DECREF(wanted_cb);
 }
 
 static void
-test_Get_Ptr8(TestBatchRunner *runner) {
-    CharBuf *cb = CB_new(64);
-
-    char *ptr8 = CB_Get_Ptr8(cb);
-    strcpy(ptr8, "0123456789");
-    CB_Set_Size(cb, 10);
-
-    TEST_INT_EQ(runner, CB_Get_Size(cb), 10, "Set_Size/Get_Size");
-
-    String *wanted = S_get_str("0123456789");
-    TEST_TRUE(runner, S_cb_equals(cb, wanted), "Get_Ptr8");
-
-    DECREF(cb);
-    DECREF(wanted);
-}
-
-/*
-static void
-test_Truncate(TestBatchRunner *runner) {
-    String  *wanted = Str_newf("a%s", smiley);
-    CharBuf *got    = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
-    CB_Truncate(got, 2);
-    TEST_TRUE(runner, S_cb_equals(got, wanted), "Truncate");
-    DECREF(wanted);
-    DECREF(got);
-}
-*/
-
-static void
 test_vcatf_percent(TestBatchRunner *runner) {
     String  *wanted = S_get_str("foo % bar");
     CharBuf *got = S_get_cb("foo");
@@ -336,8 +273,7 @@ test_Clear(TestBatchRunner *runner) {
 
 void
 TestCB_Run_IMP(TestCharBuf *self, TestBatchRunner *runner) {
-    TestBatchRunner_Plan(runner, (TestBatch*)self, 27);
-    test_new(runner);
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 20);
     test_vcatf_percent(runner);
     test_vcatf_s(runner);
     test_vcatf_null_string(runner);
@@ -353,8 +289,7 @@ TestCB_Run_IMP(TestCharBuf *self, TestBatchRunner *runner) {
     test_vcatf_f64(runner);
     test_vcatf_x32(runner);
     test_Cat(runner);
-    test_Mimic_and_Clone(runner);
-    test_Get_Ptr8(runner);
+    test_Clone(runner);
     test_Clear(runner);
 }
 


Mime
View raw message