Commit f0f1cd1dae5e7ebf2c631cc297b2b3652eaca170

Patrick Steinhardt 2020-02-07T10:51:17

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".

diff --git a/src/odb_pack.c b/src/odb_pack.c
index c93d07c..86c858d 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 7c6fc2c..fcf64f5 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 14fcb40..0000000
--- 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 841ea5b..0000000
--- 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