aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2016-06-30 09:30:41 +0300
committerDmitry Antipov2016-06-30 09:30:41 +0300
commitfd6a133fdcd6bcdc240c05cfe645cd9064f9e744 (patch)
tree73bf7750a2b46b1b986204e7841ff6ba3d1cb287 /src
parent3aeb7c35edf3ae4042717889d8bdd40e1b861be0 (diff)
downloademacs-fd6a133fdcd6bcdc240c05cfe645cd9064f9e744.tar.gz
emacs-fd6a133fdcd6bcdc240c05cfe645cd9064f9e744.zip
Minor tweaks to openp
* src/lread.c (openp): Move invariant code out of the loop and thus avoid redundant calls to memcpy. Adjust comments.
Diffstat (limited to 'src')
-rw-r--r--src/lread.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/lread.c b/src/lread.c
index 5c47f78f8e4..ecd482793a9 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1464,6 +1464,8 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
1464 1464
1465 for (; CONSP (path); path = XCDR (path)) 1465 for (; CONSP (path); path = XCDR (path))
1466 { 1466 {
1467 ptrdiff_t baselen, prefixlen;
1468
1467 filename = Fexpand_file_name (str, XCAR (path)); 1469 filename = Fexpand_file_name (str, XCAR (path));
1468 if (!complete_filename_p (filename)) 1470 if (!complete_filename_p (filename))
1469 /* If there are non-absolute elts in PATH (eg "."). */ 1471 /* If there are non-absolute elts in PATH (eg "."). */
@@ -1485,6 +1487,14 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
1485 fn = SAFE_ALLOCA (fn_size); 1487 fn = SAFE_ALLOCA (fn_size);
1486 } 1488 }
1487 1489
1490 /* Copy FILENAME's data to FN but remove starting /: if any. */
1491 prefixlen = ((SCHARS (filename) > 2
1492 && SREF (filename, 0) == '/'
1493 && SREF (filename, 1) == ':')
1494 ? 2 : 0);
1495 baselen = SBYTES (filename) - prefixlen;
1496 memcpy (fn, SDATA (filename) + prefixlen, baselen);
1497
1488 /* Loop over suffixes. */ 1498 /* Loop over suffixes. */
1489 for (tail = NILP (suffixes) ? list1 (empty_unibyte_string) : suffixes; 1499 for (tail = NILP (suffixes) ? list1 (empty_unibyte_string) : suffixes;
1490 CONSP (tail); tail = XCDR (tail)) 1500 CONSP (tail); tail = XCDR (tail))
@@ -1493,16 +1503,10 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
1493 ptrdiff_t fnlen, lsuffix = SBYTES (suffix); 1503 ptrdiff_t fnlen, lsuffix = SBYTES (suffix);
1494 Lisp_Object handler; 1504 Lisp_Object handler;
1495 1505
1496 /* Concatenate path element/specified name with the suffix. 1506 /* Make complete filename by appending SUFFIX. */
1497 If the directory starts with /:, remove that. */ 1507 memcpy (fn + baselen, SDATA (suffix), lsuffix + 1);
1498 int prefixlen = ((SCHARS (filename) > 2 1508 fnlen = baselen + lsuffix;
1499 && SREF (filename, 0) == '/' 1509
1500 && SREF (filename, 1) == ':')
1501 ? 2 : 0);
1502 fnlen = SBYTES (filename) - prefixlen;
1503 memcpy (fn, SDATA (filename) + prefixlen, fnlen);
1504 memcpy (fn + fnlen, SDATA (suffix), lsuffix + 1);
1505 fnlen += lsuffix;
1506 /* Check that the file exists and is not a directory. */ 1510 /* Check that the file exists and is not a directory. */
1507 /* We used to only check for handlers on non-absolute file names: 1511 /* We used to only check for handlers on non-absolute file names:
1508 if (absolute) 1512 if (absolute)