* buffer.c (init_buffer): Use precalculated len, adjust if needed.
* font.c (Ffont_xlfd_name): Likewise. Change to call make_string.
* lread.c (openp): Likewise.
+2012-07-10 Dmitry Antipov <dmantipov@yandex.ru>
+
+ Avoid calls to strlen in miscellaneous functions.
+ * buffer.c (init_buffer): Use precalculated len, adjust if needed.
+ * font.c (Ffont_xlfd_name): Likewise. Change to call make_string.
+ * lread.c (openp): Likewise.
+
2012-07-10 Dmitry Antipov <dmantipov@yandex.ru>
Avoid calls to strlen in path processing functions.
srclen argument and return the length of result. Adjust users
accordingly.
(directory_file_name): Fix comment. Change to add srclen argument,
- swap 1nd and 2st arguments to obey the common convention. Adjust
+ swap 1st and 2nd arguments to obey the common convention. Adjust
users accordingly.
* filelock.c (fill_in_lock_file_name): Avoid calls to strlen.
fatal ("`get_current_dir_name' failed: %s\n", strerror (errno));
pwd[len] = DIRECTORY_SEP;
pwd[len + 1] = '\0';
+ len++;
}
- BVAR (current_buffer, directory) = make_unibyte_string (pwd, strlen (pwd));
+ BVAR (current_buffer, directory) = make_unibyte_string (pwd, len);
if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))
/* At this moment, we still don't know how to decode the
directory name. So, we keep the bytes in multibyte form so
(Lisp_Object font, Lisp_Object fold_wildcards)
{
char name[256];
- int pixel_size = 0;
+ int namelen, pixel_size = 0;
CHECK_FONT (font);
if (NILP (fold_wildcards))
return font_name;
strcpy (name, SSDATA (font_name));
+ namelen = SBYTES (font_name);
goto done;
}
pixel_size = XFONT_OBJECT (font)->pixel_size;
}
- if (font_unparse_xlfd (font, pixel_size, name, 256) < 0)
+ namelen = font_unparse_xlfd (font, pixel_size, name, 256);
+ if (namelen < 0)
return Qnil;
done:
if (! NILP (fold_wildcards))
while ((p1 = strstr (p0, "-*-*")))
{
strcpy (p1, p1 + 2);
+ namelen -= 2;
p0 = p1;
}
}
- return build_string (name);
+ return make_string (name, namelen);
}
DEFUN ("clear-font-cache", Fclear_font_cache, Sclear_font_cache, 0, 0, 0,
for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes;
CONSP (tail); tail = XCDR (tail))
{
- ptrdiff_t lsuffix = SBYTES (XCAR (tail));
+ ptrdiff_t fnlen, lsuffix = SBYTES (XCAR (tail));
Lisp_Object handler;
int exists;
&& SREF (filename, 0) == '/'
&& SREF (filename, 1) == ':')
{
- strncpy (fn, SSDATA (filename) + 2,
- SBYTES (filename) - 2);
- fn[SBYTES (filename) - 2] = 0;
+ fnlen = SBYTES (filename) - 2;
+ strncpy (fn, SSDATA (filename) + 2, fnlen);
+ fn[fnlen] = '\0';
}
else
{
- strncpy (fn, SSDATA (filename),
- SBYTES (filename));
- fn[SBYTES (filename)] = 0;
+ fnlen = SBYTES (filename);
+ strncpy (fn, SSDATA (filename), fnlen);
+ fn[fnlen] = '\0';
}
if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
- strncat (fn, SSDATA (XCAR (tail)), lsuffix);
-
+ {
+ strncat (fn, SSDATA (XCAR (tail)), lsuffix);
+ fnlen += 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)
handler = Ffind_file_name_handler (filename, Qfile_exists_p);
It's not clear why that was the case and it breaks things like
(load "/bar.el") where the file is actually "/bar.el.gz". */
- string = build_string (fn);
+ string = make_string (fn, fnlen);
handler = Ffind_file_name_handler (string, Qfile_exists_p);
if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate))
{