summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/piece-table.c6
-rw-r--r--src/text-buffer.c9
-rw-r--r--src/text-buffer.h8
3 files changed, 10 insertions, 13 deletions
diff --git a/src/piece-table.c b/src/piece-table.c
index fa7cd48..24e3671 100644
--- a/src/piece-table.c
+++ b/src/piece-table.c
@@ -317,8 +317,8 @@ piece_table_create (char *orig, size_t size)
void
piece_table_destroy (piece_table *pt)
{
- text_buffer_free (&pt->orig);
- text_buffer_free (&pt->add);
+ text_buffer_clear (&pt->orig);
+ text_buffer_clear (&pt->add);
piece_buffer_destroy (pt->pieces);
free (pt);
}
@@ -357,7 +357,7 @@ piece_table_optimize (piece_table *pt)
piece_table_to_string (pt, buff, pt->length);
text_buffer_fill (&pt->orig, buff, pt->length);
free (buff);
- text_buffer_empty (&pt->add);
+ text_buffer_clear (&pt->add);
text_buffer_init (&pt->add);
piece_buffer_empty (pt->pieces);
diff --git a/src/text-buffer.c b/src/text-buffer.c
index caa1c3e..215e446 100644
--- a/src/text-buffer.c
+++ b/src/text-buffer.c
@@ -55,7 +55,7 @@ text_buffer_index (text_buffer *tb, size_t pos)
}
void
-text_buffer_empty (text_buffer *tb)
+text_buffer_clear (text_buffer *tb)
{
free (tb->contents);
text_buffer_init (tb);
@@ -74,10 +74,3 @@ text_buffer_fill (text_buffer *tb, char *fill, size_t size)
tb->contents[i] = fill[i];
}
}
-
-void
-text_buffer_free (text_buffer *tb)
-{
- free (tb->contents);
- text_buffer_init (tb);
-}
diff --git a/src/text-buffer.h b/src/text-buffer.h
index 5361534..3c85816 100644
--- a/src/text-buffer.h
+++ b/src/text-buffer.h
@@ -15,6 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/*
+ * This is a growable char buffer, it grows automatically on append.
+ * It must be cleared after use as it allocates memory.
+ */
+
#ifndef TEXT_BUFFER_H
#define TEXT_BUFFER_H
@@ -32,8 +37,7 @@ void text_buffer_init (text_buffer *tb);
void text_buffer_resize (text_buffer *tb, size_t size);
void text_buffer_append (text_buffer *tb, char c);
char text_buffer_index (text_buffer *tb, size_t pos);
-void text_buffer_empty (text_buffer *tb);
void text_buffer_fill (text_buffer *tb, char *fill, size_t size);
-void text_buffer_free (text_buffer *tb);
+void text_buffer_clear (text_buffer *tb);
#endif /* TEXT_BUFFER_H */