summaryrefslogtreecommitdiff
path: root/src/indexer.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2012-12-07 19:23:16 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2012-12-07 19:24:55 +0100
commit6481a68d49ad2e975dd0f3297d8058dcd3fd7d62 (patch)
treefc7ad74578bd1ff8eaf3663875b2bb89d8b13ddb /src/indexer.c
parent0249a5032ef6fc27d1f2b974aafdb38ab61f81bc (diff)
downloadlibgit2-6481a68d49ad2e975dd0f3297d8058dcd3fd7d62.tar.gz
indexer: move the temporary buffers into the indexer object
Storing 4kB or 8kB in the stack is not very gentle. As this part has to be linear, put the buffer into the indexer object so we allocate it once in the heap.
Diffstat (limited to 'src/indexer.c')
-rw-r--r--src/indexer.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/indexer.c b/src/indexer.c
index f78ca5774..2fb780412 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -55,6 +55,7 @@ struct git_indexer_stream {
git_oid hash;
git_transfer_progress_callback progress_cb;
void *progress_payload;
+ char objbuf[8*1024];
};
struct delta_info {
@@ -204,18 +205,17 @@ static void hash_header(git_hash_ctx *ctx, git_off_t len, git_otype type)
git_hash_update(ctx, buffer, hdrlen);
}
-static int hash_object_stream(git_hash_ctx *ctx, git_packfile_stream *stream)
+static int hash_object_stream(git_indexer_stream *idx, git_packfile_stream *stream)
{
- char buffer[8*1024];
ssize_t read;
- assert(ctx && stream);
+ assert(idx && stream);
do {
- if ((read = git_packfile_stream_read(stream, buffer, sizeof(buffer))) < 0)
+ if ((read = git_packfile_stream_read(stream, idx->objbuf, sizeof(idx->objbuf))) < 0)
break;
- git_hash_update(ctx, buffer, read);
+ git_hash_update(&idx->hash_ctx, idx->objbuf, read);
} while (read > 0);
if (read < 0)
@@ -244,15 +244,14 @@ static int advance_delta_offset(git_indexer_stream *idx, git_otype type)
}
/* Read from the stream and discard any output */
-static int read_object_stream(git_packfile_stream *stream)
+static int read_object_stream(git_indexer_stream *idx, git_packfile_stream *stream)
{
- char buffer[4*1024];
ssize_t read;
assert(stream);
do {
- read = git_packfile_stream_read(stream, buffer, sizeof(buffer));
+ read = git_packfile_stream_read(stream, idx->objbuf, sizeof(idx->objbuf));
} while (read > 0);
if (read < 0)
@@ -507,9 +506,9 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
}
if (idx->have_delta) {
- error = read_object_stream(stream);
+ error = read_object_stream(idx, stream);
} else {
- error = hash_object_stream(&idx->hash_ctx, stream);
+ error = hash_object_stream(idx, stream);
}
idx->off = stream->curpos;