Skip to content

Commit f0f1cd1

Browse files
committed
sha1_lookup: inline its only function into "pack.c"
The file "sha1_lookup.c" contains a single function `sha1_position` only which is used only in the packfile implementation. As the function is comparatively small, to enable the compiler to optimize better and to remove symbol visibility, move it into "pack.c".
1 parent bd6b1c4 commit f0f1cd1

File tree

4 files changed

+21
-56
lines changed

4 files changed

+21
-56
lines changed

src/odb_pack.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "hash.h"
1616
#include "odb.h"
1717
#include "delta.h"
18-
#include "sha1_lookup.h"
1918
#include "mwindow.h"
2019
#include "pack.h"
2120

src/pack.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "mwindow.h"
1313
#include "odb.h"
1414
#include "oid.h"
15-
#include "sha1_lookup.h"
1615

1716
/* Option to bypass checking existence of '.keep' files */
1817
bool git_disable_pack_keep_file_checks = false;
@@ -1239,6 +1238,27 @@ int git_pack_foreach_entry(
12391238
return error;
12401239
}
12411240

1241+
static int sha1_position(const void *table, size_t stride, unsigned lo,
1242+
unsigned hi, const unsigned char *key)
1243+
{
1244+
const unsigned char *base = table;
1245+
1246+
while (lo < hi) {
1247+
unsigned mi = (lo + hi) / 2;
1248+
int cmp = git_oid__hashcmp(base + mi * stride, key);
1249+
1250+
if (!cmp)
1251+
return mi;
1252+
1253+
if (cmp > 0)
1254+
hi = mi;
1255+
else
1256+
lo = mi+1;
1257+
}
1258+
1259+
return -((int)lo)-1;
1260+
}
1261+
12421262
static int pack_entry_find_offset(
12431263
off64_t *offset_out,
12441264
git_oid *found_oid,

src/sha1_lookup.c

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/sha1_lookup.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)