Windows: boost startup by avoiding a static dependency on shell32.dll
authorJohannes Sixt <j6t@kdbg.org>
Fri, 15 Jan 2010 20:12:16 +0000 (21:12 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 Jan 2010 00:43:51 +0000 (16:43 -0800)
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>
compat/mingw.c
index 0d73f15fa894cb0ded20f0cdd1f7fec3da1643f1..2afc978dfd2dfd74ccb481af6e9618b71a7e3caf 100644 (file)
@@ -3,8 +3,6 @@
 #include <conio.h>
 #include "../strbuf.h"
 
-#include <shellapi.h>
-
 static int err_win_to_posix(DWORD winerr)
 {
        int error = ENOSYS;
@@ -1338,8 +1336,22 @@ static const char *make_backslash_path(const char *path)
 void mingw_open_html(const char *unixpath)
 {
        const char *htmlpath = make_backslash_path(unixpath);
+       typedef HINSTANCE (WINAPI *T)(HWND, const char *,
+                       const char *, const char *, const char *, INT);
+       T ShellExecute;
+       HMODULE shell32;
+
+       shell32 = LoadLibrary("shell32.dll");
+       if (!shell32)
+               die("cannot load shell32.dll");
+       ShellExecute = (T)GetProcAddress(shell32, "ShellExecuteA");
+       if (!ShellExecute)
+               die("cannot run browser");
+
        printf("Launching default browser to display HTML ...\n");
        ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
+
+       FreeLibrary(shell32);
 }
 
 int link(const char *oldpath, const char *newpath)