From cc5e1bf992470e0d514c743e75a0325c8b592f38 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 21 Apr 2018 13:14:08 +0200 Subject: gettext: avoid initialization if the locale dir is not present The runtime of a simple `git.exe version` call on Windows is currently dominated by the gettext setup, adding a whopping ~150ms to the ~210ms total. Given that this cost is added to each and every git.exe invocation goes through common-main's invocation of git_setup_gettext(), and given that scripts have to call git.exe dozens, if not hundreds, of times, this is a substantial performance penalty. This is particularly pointless when considering that Git for Windows ships without localization (to keep the installer's size to a bearable ~34MB): all that time setting up gettext is for naught. To be clear, Git for Windows *needs* to be compiled with localization, for the following reasons: - to allow users to copy add-on localization in case they want it, and - to fix the nasty error message BUG: your vsnprintf is broken (returned -1) by using libgettext's override of vsnprintf() that does not share the behavior of msvcrt.dll's version of vsnprintf(). So let's be smart about it and skip setting up gettext if the locale directory is not even present. Since localization might be missing for not-yet-supported locales, this will not break anything. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- gettext.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gettext.c') diff --git a/gettext.c b/gettext.c index 6b64d5c2e8..3eb20c5f95 100644 --- a/gettext.c +++ b/gettext.c @@ -163,6 +163,9 @@ void git_setup_gettext(void) if (!podir) podir = system_path(GIT_LOCALE_PATH); + if (!is_directory(podir)) + return; + bindtextdomain("git", podir); setlocale(LC_MESSAGES, ""); setlocale(LC_TIME, ""); -- cgit v1.3 From 0210231b0803f881bf765bb2d7284c119c6ce9b6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 21 Apr 2018 13:14:28 +0200 Subject: git_setup_gettext: plug memory leak The system_path() function returns a freshly-allocated string. We need to release it. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- gettext.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'gettext.c') diff --git a/gettext.c b/gettext.c index 3eb20c5f95..4f59dfa3d1 100644 --- a/gettext.c +++ b/gettext.c @@ -159,18 +159,23 @@ static void init_gettext_charset(const char *domain) void git_setup_gettext(void) { const char *podir = getenv(GIT_TEXT_DOMAIN_DIR_ENVIRONMENT); + char *p = NULL; if (!podir) - podir = system_path(GIT_LOCALE_PATH); + podir = p = system_path(GIT_LOCALE_PATH); - if (!is_directory(podir)) + if (!is_directory(podir)) { + free(p); return; + } bindtextdomain("git", podir); setlocale(LC_MESSAGES, ""); setlocale(LC_TIME, ""); init_gettext_charset("git"); textdomain("git"); + + free(p); } /* return the number of columns of string 's' in current locale */ -- cgit v1.3