@matheusbsbs / matheus-bagliano / commits / 6e0b8ed6d3
Fork 0

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 <junkio@cox.net>

Junio C Hamano committed May 7, 2007 at 01:14 UTC 6e0b8ed6d35d0ed94b22652d6e8545b610cc43ab
1 file changed +4 -68
diff.c
+4 -68
@@ -16,8 +16,6 @@
16 #define FAST_WORKING_DIRECTORY 1
17 #endif
18
19 -static int use_size_cache;
20 -
19 static int diff_detect_rename_default;
20 static int diff_rename_limit_default = -1;
21 static int diff_use_color_default;
@@ -1408,55 +1406,6 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
1406 return 1;
1407 }
1408
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 -
1409 static int populate_from_stdin(struct diff_filespec *s)
1410 {
1411 #define INCREMENT 1024
@@ -1512,12 +1461,12 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
1461 if (S_ISDIR(s->mode))
1462 return -1;
1463
1515 - if (!use_size_cache)
1516 - size_only = 0;
1517 -
1464 if (s->data)
1465 return 0;
1466
1467 + if (size_only && 0 < s->size)
1468 + return 0;
1469 +
1470 if (S_ISDIRLNK(s->mode))
1471 return diff_populate_gitlink(s, size_only);
1472
@@ -1579,19 +1528,8 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
1528 }
1529 else {
1530 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)
1532 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 - }
1533 else {
1534 s->data = read_sha1_file(s->sha1, &type, &s->size);
1535 s->should_free = 1;
@@ -2102,8 +2040,6 @@ int diff_setup_done(struct diff_options *options)
2040 */
2041 read_cache();
2042 }
2105 - if (options->setup & DIFF_SETUP_USE_SIZE_CACHE)
2106 - use_size_cache = 1;
2043 if (options->abbrev <= 0 || 40 < options->abbrev)
2044 options->abbrev = 40; /* full */
2045