[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r117801: Avoid extra calls to strlen in filesystem I
From: |
Dmitry Antipov |
Subject: |
[Emacs-diffs] trunk r117801: Avoid extra calls to strlen in filesystem I/O routines. |
Date: |
Mon, 01 Sep 2014 16:06:33 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 117801
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Mon 2014-09-01 20:05:43 +0400
message:
Avoid extra calls to strlen in filesystem I/O routines.
* fileio.c (Fexpand_file_name): Avoid calls to strlen if
the length of 'newdir' is known or may be precalculated.
(file_accessible_directory_p): Prefer to pass Lisp_Object,
not 'char *', and so use precalculated length.
(Ffile_accessible_directory_p):
* callproc.c (encode_current_directory, init_callproc):
* charset.c (init_charset):
* lread.c (load_path_check, load_path_default): Adjust users.
* lisp.h (file_accessible_directory_p): Tweak prototype.
modified:
src/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1438
src/callproc.c callproc.c-20091113204419-o5vbwnq5f7feedwu-248
src/charset.c charset.c-20091113204419-o5vbwnq5f7feedwu-1075
src/fileio.c fileio.c-20091113204419-o5vbwnq5f7feedwu-210
src/lisp.h lisp.h-20091113204419-o5vbwnq5f7feedwu-253
src/lread.c lread.c-20091113204419-o5vbwnq5f7feedwu-266
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2014-09-01 15:07:17 +0000
+++ b/src/ChangeLog 2014-09-01 16:05:43 +0000
@@ -1,3 +1,16 @@
+2014-09-01 Dmitry Antipov <address@hidden>
+
+ Avoid extra calls to strlen in filesystem I/O routines.
+ * fileio.c (Fexpand_file_name): Avoid calls to strlen if
+ the length of 'newdir' is known or may be precalculated.
+ (file_accessible_directory_p): Prefer to pass Lisp_Object,
+ not 'char *', and so use precalculated length.
+ (Ffile_accessible_directory_p):
+ * callproc.c (encode_current_directory, init_callproc):
+ * charset.c (init_charset):
+ * lread.c (load_path_check, load_path_default): Adjust users.
+ * lisp.h (file_accessible_directory_p): Tweak prototype.
+
2014-09-01 Eli Zaretskii <address@hidden>
* w32proc.c (w32_compare_strings): Support "C" and "POSIX"
=== modified file 'src/callproc.c'
--- a/src/callproc.c 2014-07-14 19:23:18 +0000
+++ b/src/callproc.c 2014-09-01 16:05:43 +0000
@@ -129,7 +129,7 @@
if (STRING_MULTIBYTE (dir))
dir = ENCODE_FILE (dir);
- if (! file_accessible_directory_p (SSDATA (dir)))
+ if (! file_accessible_directory_p (dir))
report_file_error ("Setting current directory",
BVAR (current_buffer, directory));
@@ -1625,12 +1625,12 @@
#endif
{
tempdir = Fdirectory_file_name (Vexec_directory);
- if (! file_accessible_directory_p (SSDATA (tempdir)))
+ if (! file_accessible_directory_p (tempdir))
dir_warning ("arch-dependent data dir", Vexec_directory);
}
tempdir = Fdirectory_file_name (Vdata_directory);
- if (! file_accessible_directory_p (SSDATA (tempdir)))
+ if (! file_accessible_directory_p (tempdir))
dir_warning ("arch-independent data dir", Vdata_directory);
sh = getenv ("SHELL");
=== modified file 'src/charset.c'
--- a/src/charset.c 2014-06-23 04:11:29 +0000
+++ b/src/charset.c 2014-09-01 16:05:43 +0000
@@ -2298,7 +2298,7 @@
{
Lisp_Object tempdir;
tempdir = Fexpand_file_name (build_string ("charsets"), Vdata_directory);
- if (! file_accessible_directory_p (SSDATA (tempdir)))
+ if (! file_accessible_directory_p (tempdir))
{
/* This used to be non-fatal (dir_warning), but it should not
happen, and if it does sooner or later it will cause some
=== modified file 'src/fileio.c'
--- a/src/fileio.c 2014-08-11 00:59:34 +0000
+++ b/src/fileio.c 2014-09-01 16:05:43 +0000
@@ -889,7 +889,7 @@
bool collapse_newdir = 1;
bool is_escaped = 0;
#endif /* DOS_NT */
- ptrdiff_t length;
+ ptrdiff_t length, newdirlen;
Lisp_Object handler, result, handled_name;
bool multibyte;
Lisp_Object hdir;
@@ -1147,6 +1147,7 @@
append it to the current working directory. */
newdir = 0;
+ newdirlen = -1;
if (nm[0] == '~') /* prefix ~ */
{
@@ -1171,10 +1172,12 @@
else
#endif
tem = build_string (newdir);
+ newdirlen = SBYTES (tem);
if (multibyte && !STRING_MULTIBYTE (tem))
{
hdir = DECODE_FILE (tem);
newdir = SSDATA (hdir);
+ newdirlen = SBYTES (hdir);
}
#ifdef DOS_NT
collapse_newdir = 0;
@@ -1201,10 +1204,12 @@
bite us since we expect the directory to be
multibyte. */
tem = build_string (newdir);
+ newdirlen = SBYTES (tem);
if (multibyte && !STRING_MULTIBYTE (tem))
{
hdir = DECODE_FILE (tem);
newdir = SSDATA (hdir);
+ newdirlen = SBYTES (hdir);
}
nm = p;
#ifdef DOS_NT
@@ -1234,7 +1239,8 @@
Lisp_Object tem = build_string (adir);
tem = DECODE_FILE (tem);
- memcpy (adir, SSDATA (tem), SBYTES (tem) + 1);
+ newdirlen = SBYTES (tem);
+ memcpy (adir, SSDATA (tem), newdirlen + 1);
}
}
if (!adir)
@@ -1245,6 +1251,7 @@
adir[1] = ':';
adir[2] = '/';
adir[3] = 0;
+ newdirlen = 3;
}
newdir = adir;
}
@@ -1265,11 +1272,13 @@
&& !newdir)
{
newdir = SSDATA (default_directory);
+ newdirlen = SBYTES (default_directory);
#ifdef DOS_NT
/* Note if special escape prefix is present, but remove for now. */
if (newdir[0] == '/' && newdir[1] == ':')
{
is_escaped = 1;
+ newdirlen -= 2;
newdir += 2;
}
#endif
@@ -1305,14 +1314,14 @@
if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1]))
{
drive = (unsigned char) newdir[0];
+ newdirlen -= 2;
newdir += 2;
}
if (!IS_DIRECTORY_SEP (nm[0]))
{
- ptrdiff_t newlen = strlen (newdir);
- char *tmp = alloca (newlen + file_name_as_directory_slop
+ char *tmp = alloca (newdirlen + file_name_as_directory_slop
+ strlen (nm) + 1);
- file_name_as_directory (tmp, newdir, newlen, multibyte);
+ file_name_as_directory (tmp, newdir, newdirlen, multibyte);
strcat (tmp, nm);
nm = tmp;
}
@@ -1329,8 +1338,11 @@
Lisp_Object tem = build_string (adir);
tem = DECODE_FILE (tem);
- memcpy (adir, SSDATA (tem), SBYTES (tem) + 1);
+ newdirlen = SBYTES (tem);
+ memcpy (adir, SSDATA (tem), newdirlen + 1);
}
+ else
+ newdirlen = strlen (aidr);
newdir = adir;
}
@@ -1338,6 +1350,7 @@
if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1]))
{
drive = newdir[0];
+ newdirlen -= 2;
newdir += 2;
}
@@ -1349,17 +1362,18 @@
if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1])
&& !IS_DIRECTORY_SEP (newdir[2]))
{
- char *adir = strcpy (alloca (strlen (newdir) + 1), newdir);
+ char *adir = strcpy (alloca (newdirlen + 1), newdir);
char *p = adir + 2;
while (*p && !IS_DIRECTORY_SEP (*p)) p++;
p++;
while (*p && !IS_DIRECTORY_SEP (*p)) p++;
*p = 0;
newdir = adir;
+ newdirlen = strlen (adir);
}
else
#endif
- newdir = "";
+ newdirlen = 0, newdir = "";
}
}
#endif /* DOS_NT */
@@ -1368,7 +1382,8 @@
{
/* Ignore any slash at the end of newdir, unless newdir is
just "/" or "//". */
- length = strlen (newdir);
+ length = newdirlen;
+ eassert (length == strlen (newdir));
while (length > 1 && IS_DIRECTORY_SEP (newdir[length - 1])
&& ! (length == 2 && IS_DIRECTORY_SEP (newdir[0])))
length--;
@@ -2765,23 +2780,24 @@
}
absname = ENCODE_FILE (absname);
- return file_accessible_directory_p (SSDATA (absname)) ? Qt : Qnil;
+ return file_accessible_directory_p (absname) ? Qt : Qnil;
}
/* If FILE is a searchable directory or a symlink to a
searchable directory, return true. Otherwise return
false and set errno to an error number. */
bool
-file_accessible_directory_p (char const *file)
+file_accessible_directory_p (Lisp_Object file)
{
#ifdef DOS_NT
/* There's no need to test whether FILE is searchable, as the
searchable/executable bit is invented on DOS_NT platforms. */
- return file_directory_p (file);
+ return file_directory_p (SSDATA (file));
#else
/* On POSIXish platforms, use just one system call; this avoids a
race and is typically faster. */
- ptrdiff_t len = strlen (file);
+ const char *data = SSDATA (file);
+ ptrdiff_t len = SBYTES (file);
char const *dir;
bool ok;
int saved_errno;
@@ -2793,15 +2809,15 @@
"/" and "//" are distinct on some platforms, whereas "/", "///",
"////", etc. are all equivalent. */
if (! len)
- dir = file;
+ dir = data;
else
{
/* Just check for trailing '/' when deciding whether to append '/'.
That's simpler than testing the two special cases "/" and "//",
and it's a safe optimization here. */
char *buf = SAFE_ALLOCA (len + 3);
- memcpy (buf, file, len);
- strcpy (buf + len, &"/."[file[len - 1] == '/']);
+ memcpy (buf, data, len);
+ strcpy (buf + len, &"/."[data[len - 1] == '/']);
dir = buf;
}
=== modified file 'src/lisp.h'
--- a/src/lisp.h 2014-09-01 02:37:22 +0000
+++ b/src/lisp.h 2014-09-01 16:05:43 +0000
@@ -4029,7 +4029,7 @@
extern bool internal_delete_file (Lisp_Object);
extern Lisp_Object emacs_readlinkat (int, const char *);
extern bool file_directory_p (const char *);
-extern bool file_accessible_directory_p (const char *);
+extern bool file_accessible_directory_p (Lisp_Object);
extern void init_fileio (void);
extern void syms_of_fileio (void);
extern Lisp_Object make_temp_name (Lisp_Object, bool);
=== modified file 'src/lread.c'
--- a/src/lread.c 2014-07-26 13:17:25 +0000
+++ b/src/lread.c 2014-09-01 16:05:43 +0000
@@ -4213,7 +4213,7 @@
if (STRINGP (dirfile))
{
dirfile = Fdirectory_file_name (dirfile);
- if (! file_accessible_directory_p (SSDATA (dirfile)))
+ if (! file_accessible_directory_p (dirfile))
dir_warning ("Lisp directory", XCAR (path_tail));
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r117801: Avoid extra calls to strlen in filesystem I/O routines.,
Dmitry Antipov <=