Reuse cached data out of delta base cache.
A malloc() + memcpy() will always be faster than mmap() + malloc() + inflate(). If the data is already there it is certainly better to copy it straight away. With this patch below I can do 'git log drivers/scsi/ > /dev/null' about 7% faster. I bet it might be even more on those platforms with bad mmap() support. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nicolas Pitre committed
Mar 17, 2007 at 21:13 UTC
a0cba10847c85b0becc3c7045a423e3dc8a8f4ae
1 file changed
+10
-4
sha1_file.c
+10
-4
@@ -1372,7 +1372,7 @@ static unsigned long pack_entry_hash(struct packed_git *p, off_t base_offset)
1372
}
1373
1374
static void *cache_or_unpack_entry(struct packed_git *p, off_t base_offset,
1375
- unsigned long *base_size, enum object_type *type)
1375
+ unsigned long *base_size, enum object_type *type, int keep_cache)
1376
{
1377
void *ret;
1378
unsigned long hash = pack_entry_hash(p, base_offset);
@@ -1384,7 +1384,13 @@ static void *cache_or_unpack_entry(struct packed_git *p, off_t base_offset,
1384
return unpack_entry(p, base_offset, type, base_size);
1385
1386
found_cache_entry:
1387
- ent->data = NULL;
1387
+ if (!keep_cache)
1388
+ ent->data = NULL;
1389
+ else {
1390
+ ret = xmalloc(ent->size + 1);
1391
+ memcpy(ret, ent->data, ent->size);
1392
+ ((char *)ret)[ent->size] = 0;
1393
+ }
1394
*type = ent->type;
1395
*base_size = ent->size;
1396
return ret;
@@ -1418,7 +1424,7 @@ static void *unpack_delta_entry(struct packed_git *p,
1424
off_t base_offset;
1425
1426
base_offset = get_delta_base(p, w_curs, &curpos, *type, obj_offset);
1421
- base = cache_or_unpack_entry(p, base_offset, &base_size, type);
1427
+ base = cache_or_unpack_entry(p, base_offset, &base_size, type, 0);
1428
if (!base)
1429
die("failed to read delta base object"
1430
" at %"PRIuMAX" from %s",
@@ -1615,7 +1621,7 @@ static void *read_packed_sha1(const unsigned char *sha1,
1621
if (!find_pack_entry(sha1, &e, NULL))
1622
return NULL;
1623
else
1618
- return unpack_entry(e.p, e.offset, type, size);
1624
+ return cache_or_unpack_entry(e.p, e.offset, size, type, 1);
1625
}
1626
1627
/*