@@ -1722,11 +1722,8 @@ off_t find_pack_entry_one(const unsigned char *sha1,
17221722{
17231723 const uint32_t * level1_ofs = p -> index_data ;
17241724 const unsigned char * index = p -> index_data ;
1725- unsigned hi , lo , stride ;
1726- static int debug_lookup = -1 ;
1727-
1728- if (debug_lookup < 0 )
1729- debug_lookup = !!getenv ("GIT_DEBUG_LOOKUP" );
1725+ unsigned stride ;
1726+ uint32_t result ;
17301727
17311728 if (!index ) {
17321729 if (open_pack_index (p ))
@@ -1739,33 +1736,15 @@ off_t find_pack_entry_one(const unsigned char *sha1,
17391736 index += 8 ;
17401737 }
17411738 index += 4 * 256 ;
1742- hi = ntohl (level1_ofs [* sha1 ]);
1743- lo = ((* sha1 == 0x0 ) ? 0 : ntohl (level1_ofs [* sha1 - 1 ]));
17441739 if (p -> index_version > 1 ) {
17451740 stride = 20 ;
17461741 } else {
17471742 stride = 24 ;
17481743 index += 4 ;
17491744 }
17501745
1751- if (debug_lookup )
1752- printf ("%02x%02x%02x... lo %u hi %u nr %" PRIu32 "\n" ,
1753- sha1 [0 ], sha1 [1 ], sha1 [2 ], lo , hi , p -> num_objects );
1754-
1755- while (lo < hi ) {
1756- unsigned mi = lo + (hi - lo ) / 2 ;
1757- int cmp = hashcmp (index + mi * stride , sha1 );
1758-
1759- if (debug_lookup )
1760- printf ("lo %u hi %u rg %u mi %u\n" ,
1761- lo , hi , hi - lo , mi );
1762- if (!cmp )
1763- return nth_packed_object_offset (p , mi );
1764- if (cmp > 0 )
1765- hi = mi ;
1766- else
1767- lo = mi + 1 ;
1768- }
1746+ if (bsearch_hash (sha1 , level1_ofs , index , stride , & result ))
1747+ return nth_packed_object_offset (p , result );
17691748 return 0 ;
17701749}
17711750
0 commit comments