Skip to content

Commit 6e0b8ed

Browse files
author
Junio C Hamano
committed
diff.c: do not use a separate "size cache".
diff_filespec has a slot to record the size of the data already, so make use of it instead of a separate size cache. Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc3abdf commit 6e0b8ed

File tree

1 file changed

+4
-68
lines changed

1 file changed

+4
-68
lines changed

diff.c

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#define FAST_WORKING_DIRECTORY 1
1717
#endif
1818

19-
static int use_size_cache;
20-
2119
static int diff_detect_rename_default;
2220
static int diff_rename_limit_default = -1;
2321
static int diff_use_color_default;
@@ -1408,55 +1406,6 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
14081406
return 1;
14091407
}
14101408

1411-
static struct sha1_size_cache {
1412-
unsigned char sha1[20];
1413-
unsigned long size;
1414-
} **sha1_size_cache;
1415-
static int sha1_size_cache_nr, sha1_size_cache_alloc;
1416-
1417-
static struct sha1_size_cache *locate_size_cache(unsigned char *sha1,
1418-
int find_only,
1419-
unsigned long size)
1420-
{
1421-
int first, last;
1422-
struct sha1_size_cache *e;
1423-
1424-
first = 0;
1425-
last = sha1_size_cache_nr;
1426-
while (last > first) {
1427-
int cmp, next = (last + first) >> 1;
1428-
e = sha1_size_cache[next];
1429-
cmp = hashcmp(e->sha1, sha1);
1430-
if (!cmp)
1431-
return e;
1432-
if (cmp < 0) {
1433-
last = next;
1434-
continue;
1435-
}
1436-
first = next+1;
1437-
}
1438-
/* not found */
1439-
if (find_only)
1440-
return NULL;
1441-
/* insert to make it at "first" */
1442-
if (sha1_size_cache_alloc <= sha1_size_cache_nr) {
1443-
sha1_size_cache_alloc = alloc_nr(sha1_size_cache_alloc);
1444-
sha1_size_cache = xrealloc(sha1_size_cache,
1445-
sha1_size_cache_alloc *
1446-
sizeof(*sha1_size_cache));
1447-
}
1448-
sha1_size_cache_nr++;
1449-
if (first < sha1_size_cache_nr)
1450-
memmove(sha1_size_cache + first + 1, sha1_size_cache + first,
1451-
(sha1_size_cache_nr - first - 1) *
1452-
sizeof(*sha1_size_cache));
1453-
e = xmalloc(sizeof(struct sha1_size_cache));
1454-
sha1_size_cache[first] = e;
1455-
hashcpy(e->sha1, sha1);
1456-
e->size = size;
1457-
return e;
1458-
}
1459-
14601409
static int populate_from_stdin(struct diff_filespec *s)
14611410
{
14621411
#define INCREMENT 1024
@@ -1512,12 +1461,12 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
15121461
if (S_ISDIR(s->mode))
15131462
return -1;
15141463

1515-
if (!use_size_cache)
1516-
size_only = 0;
1517-
15181464
if (s->data)
15191465
return 0;
15201466

1467+
if (size_only && 0 < s->size)
1468+
return 0;
1469+
15211470
if (S_ISDIRLNK(s->mode))
15221471
return diff_populate_gitlink(s, size_only);
15231472

@@ -1579,19 +1528,8 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
15791528
}
15801529
else {
15811530
enum object_type type;
1582-
struct sha1_size_cache *e;
1583-
1584-
if (size_only && use_size_cache &&
1585-
(e = locate_size_cache(s->sha1, 1, 0)) != NULL) {
1586-
s->size = e->size;
1587-
return 0;
1588-
}
1589-
1590-
if (size_only) {
1531+
if (size_only)
15911532
type = sha1_object_info(s->sha1, &s->size);
1592-
if (use_size_cache && 0 < type)
1593-
locate_size_cache(s->sha1, 0, s->size);
1594-
}
15951533
else {
15961534
s->data = read_sha1_file(s->sha1, &type, &s->size);
15971535
s->should_free = 1;
@@ -2102,8 +2040,6 @@ int diff_setup_done(struct diff_options *options)
21022040
*/
21032041
read_cache();
21042042
}
2105-
if (options->setup & DIFF_SETUP_USE_SIZE_CACHE)
2106-
use_size_cache = 1;
21072043
if (options->abbrev <= 0 || 40 < options->abbrev)
21082044
options->abbrev = 40; /* full */
21092045

0 commit comments

Comments
 (0)