unpack_delta_entry(): reduce memory footprint.
Currently we unpack the delta data from the pack and then unpack the base object to apply that delta data to it. When getting an object that is deeply deltified, we can reduce memory footprint by unpacking the base object first and then unpacking the delta data, because we will need to keep at most one delta data in memory that way. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Mar 19, 2006 at 13:43 UTC
67686d95044e56475669ff1306448e41a794a865
1 file changed
+10
-8
sha1_file.c
+10
-8
@@ -973,6 +973,16 @@ static void *unpack_delta_entry(unsigned char *base_sha1,
973
974
if (left < 20)
975
die("truncated pack file");
976
+
977
+ /* The base entry _must_ be in the same pack */
978
+ if (!find_pack_entry_one(base_sha1, &base_ent, p))
979
+ die("failed to find delta-pack base object %s",
980
+ sha1_to_hex(base_sha1));
981
+ base = unpack_entry_gently(&base_ent, type, &base_size);
982
+ if (!base)
983
+ die("failed to read delta-pack base object %s",
984
+ sha1_to_hex(base_sha1));
985
+
986
data = base_sha1 + 20;
987
data_size = left - 20;
988
delta_data = xmalloc(delta_size);
@@ -990,14 +1000,6 @@ static void *unpack_delta_entry(unsigned char *base_sha1,
1000
if ((st != Z_STREAM_END) || stream.total_out != delta_size)
1001
die("delta data unpack failed");
1002
993
- /* The base entry _must_ be in the same pack */
994
- if (!find_pack_entry_one(base_sha1, &base_ent, p))
995
- die("failed to find delta-pack base object %s",
996
- sha1_to_hex(base_sha1));
997
- base = unpack_entry_gently(&base_ent, type, &base_size);
998
- if (!base)
999
- die("failed to read delta-pack base object %s",
1000
- sha1_to_hex(base_sha1));
1003
result = patch_delta(base, base_size,
1004
delta_data, delta_size,
1005
&result_size);