You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/09/13 20:31:48 UTC

[lucy-commits] [16/17] git commit: refs/heads/cfish-string-prep1 - Remove Grow, Mimic, and Set_Size methods from String

Remove Grow, Mimic, and Set_Size methods from String


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

Branch: refs/heads/cfish-string-prep1
Commit: f0a51981966374f26304ebdbaba5892d913ef0d3
Parents: ec1f886
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Sep 10 01:56:20 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Sep 13 20:16:12 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/String.c       | 48 --------------------
 clownfish/runtime/core/Clownfish/String.cfh     | 26 +----------
 .../runtime/core/Clownfish/Test/TestString.c    | 25 ++++------
 3 files changed, 10 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/f0a51981/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index d5b5832..a5544e0 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -175,22 +175,6 @@ Str_Hash_Sum_IMP(String *self) {
 }
 
 static void
-S_grow(String *self, size_t size) {
-    if (size >= self->cap) {
-        Str_Grow(self, size);
-    }
-}
-
-char*
-Str_Grow_IMP(String *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
 S_die_invalid_utf8(const char *text, size_t size, const char *file, int line,
                    const char *func) {
     fprintf(stderr, "Invalid UTF-8, aborting: '");
@@ -308,26 +292,6 @@ Str_Clone_IMP(String *self) {
     return Str_new_from_trusted_utf8(self->ptr, self->size);
 }
 
-void
-Str_Mimic_Str_IMP(String *self, const char* ptr, size_t size) {
-    if (!StrHelp_utf8_valid(ptr, size)) {
-        DIE_INVALID_UTF8(ptr, size);
-    }
-    if (size >= self->cap) { S_grow(self, size); }
-    memmove(self->ptr, ptr, size);
-    self->size = size;
-    self->ptr[size] = '\0';
-}
-
-void
-Str_Mimic_IMP(String *self, Obj *other) {
-    String *twin = (String*)CERTIFY(other, STRING);
-    if (twin->size >= self->cap) { S_grow(self, twin->size); }
-    memmove(self->ptr, twin->ptr, twin->size);
-    self->size = twin->size;
-    self->ptr[twin->size] = '\0';
-}
-
 String*
 Str_Cat_IMP(String *self, const String *other) {
     return Str_Cat_Trusted_UTF8(self, other->ptr, other->size);
@@ -526,11 +490,6 @@ Str_less_than(const void *va, const void *vb) {
     return Str_compare(va, vb) < 0 ? true : false;
 }
 
-void
-Str_Set_Size_IMP(String *self, size_t size) {
-    self->size = size;
-}
-
 size_t
 Str_Get_Size_IMP(String *self) {
     return self->size;
@@ -592,13 +551,6 @@ ViewCB_Destroy_IMP(ViewCharBuf *self) {
     SUPER_DESTROY(self, STRING);
 }
 
-char*
-ViewCB_Grow_IMP(ViewCharBuf *self, size_t size) {
-    UNUSED_VAR(size);
-    THROW(ERR, "Can't grow a ViewCharBuf ('%o')", self);
-    UNREACHABLE_RETURN(char*);
-}
-
 /*****************************************************************/
 
 StackString*

http://git-wip-us.apache.org/repos/asf/lucy/blob/f0a51981/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index ecd7bfb..876657d 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -17,7 +17,7 @@
 parcel Clownfish;
 
 /**
- * Growable buffer holding Unicode characters.
+ * Immutable string holding Unicode characters.
  */
 
 class Clownfish::String cnick Str
@@ -97,12 +97,6 @@ class Clownfish::String cnick Str
     inert bool
     less_than(const void *va, const void *vb);
 
-    public void
-    Mimic(String *self, Obj *other);
-
-    void
-    Mimic_Str(String *self, const char *ptr, size_t size);
-
     /** Return the concatenation of the String and <code>other</code>.
      */
     incremented String*
@@ -136,15 +130,6 @@ class Clownfish::String cnick Str
     public double
     To_F64(String *self);
 
-    /** Assign more memory to the String, if it doesn't already have enough
-     * room to hold a string of <code>size</code> bytes.  Cannot shrink the
-     * allocation.
-     *
-     * @return a pointer to the raw buffer.
-     */
-    char*
-    Grow(String *self, size_t size);
-
     /** Test whether the String starts with the content of another.
      */
     bool
@@ -184,11 +169,6 @@ class Clownfish::String cnick Str
     size_t
     Length(String *self);
 
-    /** Set the String's <code>size</code> attribute.
-     */
-    void
-    Set_Size(String *self, size_t size);
-
     /** Get the String's <code>size</code> attribute.
      */
     size_t
@@ -295,10 +275,6 @@ class Clownfish::ViewCharBuf cnick ViewCB
     inert ViewCharBuf*
     init(ViewCharBuf *self, const char *utf8, size_t size);
 
-    /** Throws an error. */
-    char*
-    Grow(ViewCharBuf *self, size_t size);
-
     public void
     Destroy(ViewCharBuf *self);
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/f0a51981/clownfish/runtime/core/Clownfish/Test/TestString.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestString.c b/clownfish/runtime/core/Clownfish/Test/TestString.c
index ec37a2b..31143fc 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestString.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestString.c
@@ -98,19 +98,10 @@ test_Cat(TestBatchRunner *runner) {
 }
 
 static void
-test_Mimic_and_Clone(TestBatchRunner *runner) {
+test_Clone(TestBatchRunner *runner) {
     String *wanted = S_get_str("foo");
     String *got    = S_get_str("bar");
 
-    Str_Mimic(got, (Obj*)wanted);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "Mimic");
-    DECREF(got);
-
-    got = S_get_str("bar");
-    Str_Mimic_Str(got, "foo", 3);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "Mimic_Str");
-    DECREF(got);
-
     got = Str_Clone(wanted);
     TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "Clone");
     DECREF(got);
@@ -133,8 +124,9 @@ test_Find(TestBatchRunner *runner) {
 
     string = S_get_str("afoo");
     TEST_TRUE(runner, Str_Find(string, substring) == 1, "Find after first");
-    Str_Set_Size(string, 3);
-    TEST_TRUE(runner, Str_Find(string, substring) == -1, "Don't overrun");
+    // TODO: Enable this test when we have real substrings.
+    /*Str_Set_Size(string, 3);
+    TEST_TRUE(runner, Str_Find(string, substring) == -1, "Don't overrun");*/
     DECREF(string);
 
     string = S_get_str("afood");
@@ -244,13 +236,14 @@ test_To_F64(TestBatchRunner *runner) {
     TEST_TRUE(runner, difference < 0.001, "To_F64 negative");
     DECREF(string);
 
-    string = S_get_str("1.59");
+    // TODO: Enable this test when we have real substrings.
+    /*string = S_get_str("1.59");
     double value_full = Str_To_F64(string);
     Str_Set_Size(string, 3);
     double value_short = Str_To_F64(string);
     TEST_TRUE(runner, value_short < value_full,
               "TO_F64 doesn't run past end of string");
-    DECREF(string);
+    DECREF(string);*/
 }
 
 static void
@@ -488,9 +481,9 @@ test_iterator_substring(TestBatchRunner *runner) {
 
 void
 TestStr_Run_IMP(TestString *self, TestBatchRunner *runner) {
-    TestBatchRunner_Plan(runner, (TestBatch*)self, 103);
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 99);
     test_Cat(runner);
-    test_Mimic_and_Clone(runner);
+    test_Clone(runner);
     test_Code_Point_At_and_From(runner);
     test_Find(runner);
     test_SubString(runner);