Merge pull request #1126 from carlosmn/indexer-buffer indexer: move the temporary buffers into the indexer object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/src/indexer.c b/src/indexer.c
index f78ca57..2fb7804 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;