summaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-04-04 17:04:58 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2016-04-04 17:05:19 -0700
commitb4c7869e5e1bb0bb33379b25ff830e721761a7bf (patch)
tree07b81f9711ea7188421c2ac2303b442778b6c980 /src/buffer.c
parent3c623c26ae7d695746e05d8a2e16a67a6256b024 (diff)
downloademacs-b4c7869e5e1bb0bb33379b25ff830e721761a7bf.tar.gz
Prefer AUTO_STRING_WITH_LEN to make_formatted_string
* src/buffer.c (Fgenerate_new_buffer_name): * src/filelock.c (get_boot_time): * src/minibuf.c (get_minibuffer): * src/process.c (make_process): * src/xdisp.c (ensure_echo_area_buffers): Prefer AUTO_STRING_WITH_LEN + sprintf to make_formatted_string when either will do.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 62b0bc8c6f4..0e5e64f58a1 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1051,44 +1051,36 @@ it is in the sequence to be tried) even if a buffer with that name exists.
If NAME begins with a space (i.e., a buffer that is not normally
visible to users), then if buffer NAME already exists a random number
is first appended to NAME, to speed up finding a non-existent buffer. */)
- (register Lisp_Object name, Lisp_Object ignore)
+ (Lisp_Object name, Lisp_Object ignore)
{
- register Lisp_Object gentemp, tem, tem2;
- ptrdiff_t count;
- char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
+ Lisp_Object genbase;
CHECK_STRING (name);
- tem = Fstring_equal (name, ignore);
- if (!NILP (tem))
- return name;
- tem = Fget_buffer (name);
- if (NILP (tem))
+ if (!NILP (Fstring_equal (name, ignore)) || NILP (Fget_buffer (name)))
return name;
- if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */
+ if (SREF (name, 0) != ' ') /* See bug#1229. */
+ genbase = name;
+ else
{
/* Note fileio.c:make_temp_name does random differently. */
- tem2 = concat2 (name, make_formatted_string
- (number, "-%"pI"d",
- XFASTINT (Frandom (make_number (999999)))));
- tem = Fget_buffer (tem2);
- if (NILP (tem))
- return tem2;
+ char number[sizeof "-999999"];
+ int i = XFASTINT (Frandom (make_number (999999)));
+ AUTO_STRING_WITH_LEN (lnumber, number, sprintf (number, "-%d", i));
+ genbase = concat2 (name, lnumber);
+ if (NILP (Fget_buffer (genbase)))
+ return genbase;
}
- else
- tem2 = name;
- count = 1;
- while (1)
+ for (ptrdiff_t count = 1; ; count++)
{
- gentemp = concat2 (tem2, make_formatted_string
- (number, "<%"pD"d>", ++count));
- tem = Fstring_equal (gentemp, ignore);
- if (!NILP (tem))
- return gentemp;
- tem = Fget_buffer (gentemp);
- if (NILP (tem))
+ char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
+ AUTO_STRING_WITH_LEN (lnumber, number,
+ sprintf (number, "<%"pD"d>", count));
+ Lisp_Object gentemp = concat2 (genbase, lnumber);
+ if (!NILP (Fstring_equal (gentemp, ignore))
+ || NILP (Fget_buffer (gentemp)))
return gentemp;
}
}