]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.2129: MS-Windows: Checking if a file name is absolute is slow v8.2.2129
authorBram Moolenaar <Bram@vim.org>
Fri, 11 Dec 2020 19:10:50 +0000 (20:10 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 11 Dec 2020 19:10:50 +0000 (20:10 +0100)
Problem:    MS-Windows: Checking if a file name is absolute is slow.
Solution:   Do not use mch_FullName(). (closes #7033)

src/os_mswin.c
src/version.c

index 80009533c63663d3b655c533f086c41d68f590ea..096ac1bc5b6e4ac054ea86dc08a61ea6939fcb9f 100644 (file)
@@ -387,21 +387,13 @@ mch_FullName(
     int
 mch_isFullName(char_u *fname)
 {
-    // WinNT and later can use _MAX_PATH wide characters for a pathname, which
-    // means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is
-    // UTF-8.
-    char szName[_MAX_PATH * 3 + 1];
-
-    // A name like "d:/foo" and "//server/share" is absolute
-    if ((fname[0] && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\'))
-           || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\')))
-       return TRUE;
-
-    // A name that can't be made absolute probably isn't absolute.
-    if (mch_FullName(fname, (char_u *)szName, sizeof(szName) - 1, FALSE) == FAIL)
-       return FALSE;
-
-    return pathcmp((const char *)fname, (const char *)szName, -1) == 0;
+    // A name like "d:/foo" and "//server/share" is absolute.  "d:foo" is not.
+    // Another way to check is to use mch_FullName() and see if the result is
+    // the same as the name or mch_FullName() fails.  However, this has quite a
+    // bit of overhead, so let's not do that.
+    return ((ASCII_ISALPHA(fname[0]) && fname[1] == ':'
+                                     && (fname[2] == '/' || fname[2] == '\\'))
+           || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\')));
 }
 
 /*
index 24a8390f6b0619ce66cbcdbc4bcf100bd5bfee6e..9dae296a1e8362ada732a05cd3ae309e00de1ede 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2129,
 /**/
     2128,
 /**/