summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2020-02-07 10:51:17 +0100
committerPatrick Steinhardt <ps@pks.im>2020-02-07 10:52:47 +0100
commitf0f1cd1dae5e7ebf2c631cc297b2b3652eaca170 (patch)
tree705f3c3457d6fac80293d2ae102165a6e90b9869
parentbd6b1c41575e7cc011798a424b6564569887c293 (diff)
downloadlibgit2-f0f1cd1dae5e7ebf2c631cc297b2b3652eaca170.tar.gz
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".
-rw-r--r--src/odb_pack.c1
-rw-r--r--src/pack.c22
-rw-r--r--src/sha1_lookup.c35
-rw-r--r--src/sha1_lookup.h19
4 files changed, 21 insertions, 56 deletions
diff --git a/src/odb_pack.c b/src/odb_pack.c
index c93d07c46..86c858df1 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -15,7 +15,6 @@
#include "hash.h"
#include "odb.h"
#include "delta.h"
-#include "sha1_lookup.h"
#include "mwindow.h"
#include "pack.h"
diff --git a/src/pack.c b/src/pack.c
index 7c6fc2cdb..fcf64f57d 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -12,7 +12,6 @@
#include "mwindow.h"
#include "odb.h"
#include "oid.h"
-#include "sha1_lookup.h"
/* Option to bypass checking existence of '.keep' files */
bool git_disable_pack_keep_file_checks = false;
@@ -1239,6 +1238,27 @@ int git_pack_foreach_entry(
return error;
}
+static int sha1_position(const void *table, size_t stride, unsigned lo,
+ unsigned hi, const unsigned char *key)
+{
+ const unsigned char *base = table;
+
+ while (lo < hi) {
+ unsigned mi = (lo + hi) / 2;
+ int cmp = git_oid__hashcmp(base + mi * stride, key);
+
+ if (!cmp)
+ return mi;
+
+ if (cmp > 0)
+ hi = mi;
+ else
+ lo = mi+1;
+ }
+
+ return -((int)lo)-1;
+}
+
static int pack_entry_find_offset(
off64_t *offset_out,
git_oid *found_oid,
diff --git a/src/sha1_lookup.c b/src/sha1_lookup.c
deleted file mode 100644
index 14fcb40e5..000000000
--- a/src/sha1_lookup.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-
-#include "sha1_lookup.h"
-
-#include <stdio.h>
-
-#include "oid.h"
-
-int sha1_position(const void *table,
- size_t stride,
- unsigned lo, unsigned hi,
- const unsigned char *key)
-{
- const unsigned char *base = table;
-
- while (lo < hi) {
- unsigned mi = (lo + hi) / 2;
- int cmp = git_oid__hashcmp(base + mi * stride, key);
-
- if (!cmp)
- return mi;
-
- if (cmp > 0)
- hi = mi;
- else
- lo = mi+1;
- }
-
- return -((int)lo)-1;
-}
diff --git a/src/sha1_lookup.h b/src/sha1_lookup.h
deleted file mode 100644
index 841ea5b22..000000000
--- a/src/sha1_lookup.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_sha1_lookup_h__
-#define INCLUDE_sha1_lookup_h__
-
-#include "common.h"
-
-#include <stdlib.h>
-
-int sha1_position(const void *table,
- size_t stride,
- unsigned lo, unsigned hi,
- const unsigned char *key);
-
-#endif