summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4d21bec)
raw | patch | inline | side by side (parent: 4d21bec)
author | Jonathan Nieder <jrnieder@gmail.com> | |
Sat, 6 Nov 2010 17:01:28 +0000 (12:01 -0500) | ||
committer | Jonathan Nieder <jrnieder@gmail.com> | |
Sat, 26 Feb 2011 10:57:58 +0000 (04:57 -0600) |
obj_pool is inherently global and does not use the standard growing
factor alloc_nr, which makes it feel out of place in the git codebase.
Plus it is overkill for this application: all that is needed is a
buffer that can grow between requests to accomodate larger strings.
Use a strbuf instead.
As a side effect, this improves the error handling: allocation
failures will result in a clean exit instead of segfaults. It would
be nice to add a test case (using ulimit or failmalloc) but that can
wait for another day.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
factor alloc_nr, which makes it feel out of place in the git codebase.
Plus it is overkill for this application: all that is needed is a
buffer that can grow between requests to accomodate larger strings.
Use a strbuf instead.
As a side effect, this improves the error handling: allocation
failures will result in a clean exit instead of segfaults. It would
be nice to add a test case (using ulimit or failmalloc) but that can
wait for another day.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
vcs-svn/line_buffer.c | patch | blob | history |
diff --git a/vcs-svn/line_buffer.c b/vcs-svn/line_buffer.c
index f22c94f025ae720ac7f6c333d6de1a04662e7a9b..6f32f28e5436f208a0a85bdcafe4d38a1f683631 100644 (file)
--- a/vcs-svn/line_buffer.c
+++ b/vcs-svn/line_buffer.c
#include "git-compat-util.h"
#include "line_buffer.h"
-#include "obj_pool.h"
+#include "strbuf.h"
#define LINE_BUFFER_LEN 10000
#define COPY_BUFFER_LEN 4096
-/* Create memory pool for char sequence of known length */
-obj_pool_gen(blob, char, 4096)
-
static char line_buffer[LINE_BUFFER_LEN];
+static struct strbuf blob_buffer = STRBUF_INIT;
static FILE *infile;
int buffer_init(const char *filename)
char *buffer_read_string(uint32_t len)
{
- char *s;
- blob_free(blob_pool.size);
- s = blob_pointer(blob_alloc(len + 1));
- s[fread(s, 1, len, infile)] = '\0';
- return ferror(infile) ? NULL : s;
+ strbuf_reset(&blob_buffer);
+ strbuf_fread(&blob_buffer, len, infile);
+ return ferror(infile) ? NULL : blob_buffer.buf;
}
void buffer_copy_bytes(uint32_t len)
void buffer_reset(void)
{
- blob_reset();
+ strbuf_release(&blob_buffer);
}