Windows: boost startup by avoiding a static dependency on shell32.dll
This DLL is only needed to invoke the browser in a "git help" call. By looking up the only function that we need at runtime, we can avoid the startup costs of this DLL. DLL usage can be profiled with Microsoft's Dependency Walker. For example, a call to "git diff-files" loaded before: 19 DLLs after: 9 DLLs As a result, the runtime of 'make -j2 test' went down from 16:00min to 12:40min on one of my boxes. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Jan 15, 2010 at 21:12 UTC
928500e00e0a73a11f5b2296d9baa82dafa7a1a8
1 file changed
+14
-2
compat/mingw.c
+14
-2
@@ -3,8 +3,6 @@
3
#include <conio.h>
4
#include "../strbuf.h"
5
6
-#include <shellapi.h>
7
-
6
static int err_win_to_posix(DWORD winerr)
7
{
8
int error = ENOSYS;
@@ -1338,8 +1336,22 @@ static const char *make_backslash_path(const char *path)
1336
void mingw_open_html(const char *unixpath)
1337
{
1338
const char *htmlpath = make_backslash_path(unixpath);
1339
+ typedef HINSTANCE (WINAPI *T)(HWND, const char *,
1340
+ const char *, const char *, const char *, INT);
1341
+ T ShellExecute;
1342
+ HMODULE shell32;
1343
+
1344
+ shell32 = LoadLibrary("shell32.dll");
1345
+ if (!shell32)
1346
+ die("cannot load shell32.dll");
1347
+ ShellExecute = (T)GetProcAddress(shell32, "ShellExecuteA");
1348
+ if (!ShellExecute)
1349
+ die("cannot run browser");
1350
+
1351
printf("Launching default browser to display HTML ...\n");
1352
ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
1353
+
1354
+ FreeLibrary(shell32);
1355
}
1356
1357
int link(const char *oldpath, const char *newpath)