emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master fd6a133: Minor tweaks to openp


From: Dmitry Antipov
Subject: [Emacs-diffs] master fd6a133: Minor tweaks to openp
Date: Thu, 30 Jun 2016 06:50:48 +0000 (UTC)

branch: master
commit fd6a133fdcd6bcdc240c05cfe645cd9064f9e744
Author: Dmitry Antipov <address@hidden>
Commit: Dmitry Antipov <address@hidden>

    Minor tweaks to openp
    
    * src/lread.c (openp): Move invariant code out of the loop
    and thus avoid redundant calls to memcpy.  Adjust comments.
---
 src/lread.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/lread.c b/src/lread.c
index 5c47f78..ecd4827 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1464,6 +1464,8 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object 
suffixes,
 
   for (; CONSP (path); path = XCDR (path))
     {
+      ptrdiff_t baselen, prefixlen;
+
       filename = Fexpand_file_name (str, XCAR (path));
       if (!complete_filename_p (filename))
        /* If there are non-absolute elts in PATH (eg ".").  */
@@ -1485,6 +1487,14 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object 
suffixes,
          fn = SAFE_ALLOCA (fn_size);
        }
 
+      /* Copy FILENAME's data to FN but remove starting /: if any.  */
+      prefixlen = ((SCHARS (filename) > 2
+                   && SREF (filename, 0) == '/'
+                   && SREF (filename, 1) == ':')
+                  ? 2 : 0);
+      baselen = SBYTES (filename) - prefixlen;
+      memcpy (fn, SDATA (filename) + prefixlen, baselen);
+
       /* Loop over suffixes.  */
       for (tail = NILP (suffixes) ? list1 (empty_unibyte_string) : suffixes;
           CONSP (tail); tail = XCDR (tail))
@@ -1493,16 +1503,10 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object 
suffixes,
          ptrdiff_t fnlen, lsuffix = SBYTES (suffix);
          Lisp_Object handler;
 
-         /* Concatenate path element/specified name with the suffix.
-            If the directory starts with /:, remove that.  */
-         int prefixlen = ((SCHARS (filename) > 2
-                           && SREF (filename, 0) == '/'
-                           && SREF (filename, 1) == ':')
-                          ? 2 : 0);
-         fnlen = SBYTES (filename) - prefixlen;
-         memcpy (fn, SDATA (filename) + prefixlen, fnlen);
-         memcpy (fn + fnlen, SDATA (suffix), lsuffix + 1);
-         fnlen += lsuffix;
+         /* Make complete filename by appending SUFFIX.  */
+         memcpy (fn + baselen, SDATA (suffix), lsuffix + 1);
+         fnlen = baselen + lsuffix;
+
          /* Check that the file exists and is not a directory.  */
          /* We used to only check for handlers on non-absolute file names:
                if (absolute)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]