diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2016-04-27 12:00:31 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2016-05-02 17:37:26 +0200 |
commit | a97b769a0ef7fe8b301c07280c9b80233bb77643 (patch) | |
tree | b7689ab05499e22ca4b9787f12a30a437b7e9547 /src/pack.c | |
parent | 88284dfb7905c5990babb4238b7cd30bdf823500 (diff) | |
download | libgit2-cmn/faster-header.tar.gz |
odb: avoid inflating the full delta to read the headercmn/faster-header
When we read the header, we want to know the size and type of the
object. We're currently inflating the full delta in order to read the
first few bytes. This can mean hundreds of kB needlessly inflated for
large objects.
Instead use a packfile stream to read just enough so we can read the two
varints in the header and avoid inflating most of the delta.
Diffstat (limited to 'src/pack.c')
-rw-r--r-- | src/pack.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/pack.c b/src/pack.c index e7003e66d..6a700e29f 100644 --- a/src/pack.c +++ b/src/pack.c @@ -499,15 +499,14 @@ int git_packfile_resolve_header( if (type == GIT_OBJ_OFS_DELTA || type == GIT_OBJ_REF_DELTA) { size_t base_size; - git_rawobj delta; + git_packfile_stream stream; + base_offset = get_delta_base(p, &w_curs, &curpos, type, offset); git_mwindow_close(&w_curs); - error = packfile_unpack_compressed(&delta, p, &w_curs, &curpos, size, type); - git_mwindow_close(&w_curs); - if (error < 0) + if ((error = git_packfile_stream_open(&stream, p, curpos)) < 0) return error; - error = git__delta_read_header(delta.data, delta.len, &base_size, size_p); - git__free(delta.data); + error = git__delta_read_header_fromstream(&base_size, size_p, &stream); + git_packfile_stream_free(&stream); if (error < 0) return error; } else |