unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#24044: [PATCH] fileio.c: introduce make_temp_name_buf
@ 2016-07-21 10:02 Alexnader Kuleshov
  2017-10-21 23:50 ` Noam Postavsky
  0 siblings, 1 reply; 2+ messages in thread
From: Alexnader Kuleshov @ 2016-07-21 10:02 UTC (permalink / raw)
  To: 24044

[-- Attachment #1: Type: text/plain, Size: 363 bytes --]

Hello,

The make_temp_name function in a case when BASE64_P is true or when
HAVE_LONG_FILE_NAMES is
not defined builds buffer where first three characters is a PID in
base64 encoding. This leads to some of
code duplication.

Attached patch introduces make_temp_name_buf() function which will do
this functionality and allows to avoid
code duplication.

Thank you

[-- Attachment #2: 0001-fileio.c-introduce-make_temp_name_buf.patch --]
[-- Type: text/plain, Size: 2300 bytes --]

From c58d13c750901e9f47c99dd2466e95dabb3730a1 Mon Sep 17 00:00:00 2001
From: Alexander Kuleshov <kuleshovmail@gmail.com>
Date: Wed, 20 Jul 2016 18:33:55 +0600
Subject: [PATCH] fileio.c: introduce make_temp_name_buf

* src/fileio.c: New function - make_temp_name_buf. Use it in the
make_temp_name() function.
---
 src/fileio.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/fileio.c b/src/fileio.c
index b1f9d3c..a23a5fc 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -620,6 +620,16 @@ static const char make_temp_name_tbl[64] =
   '4','5','6','7','8','9','-','_'
 };
 
+/* Add 3 characters in base64 encoding to the given buffer */
+
+static char *make_temp_name_buf (char *buf, unsigned num) {
+  buf[0] = make_temp_name_tbl[num & 63], num >>= 6;
+  buf[1] = make_temp_name_tbl[num & 63], num >>= 6;
+  buf[2] = make_temp_name_tbl[num & 63], num >>= 6;
+
+  return buf;
+}
+
 static unsigned make_temp_name_count, make_temp_name_count_initialized_p;
 
 /* Value is a temporary file name starting with PREFIX, a string.
@@ -659,9 +669,7 @@ make_temp_name (Lisp_Object prefix, bool base64_p)
 
   if (base64_p)
     {
-      pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6;
-      pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6;
-      pidbuf[2] = make_temp_name_tbl[pid & 63], pid >>= 6;
+      make_temp_name_buf (pidbuf, pid);
       pidlen = 3;
     }
   else
@@ -669,9 +677,7 @@ make_temp_name (Lisp_Object prefix, bool base64_p)
 #ifdef HAVE_LONG_FILE_NAMES
       pidlen = sprintf (pidbuf, "%"pMd, pid);
 #else
-      pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6;
-      pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6;
-      pidbuf[2] = make_temp_name_tbl[pid & 63], pid >>= 6;
+      make_temp_name_buf (pidbuf, pid);
       pidlen = 3;
 #endif
     }
@@ -705,9 +711,7 @@ make_temp_name (Lisp_Object prefix, bool base64_p)
     {
       unsigned num = make_temp_name_count;
 
-      p[0] = make_temp_name_tbl[num & 63], num >>= 6;
-      p[1] = make_temp_name_tbl[num & 63], num >>= 6;
-      p[2] = make_temp_name_tbl[num & 63], num >>= 6;
+      make_temp_name_buf (p, num);
 
       /* Poor man's congruential RN generator.  Replace with
          ++make_temp_name_count for debugging.  */
-- 
2.8.0.rc3.922.g2bcc146


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#24044: [PATCH] fileio.c: introduce make_temp_name_buf
  2016-07-21 10:02 bug#24044: [PATCH] fileio.c: introduce make_temp_name_buf Alexnader Kuleshov
@ 2017-10-21 23:50 ` Noam Postavsky
  0 siblings, 0 replies; 2+ messages in thread
From: Noam Postavsky @ 2017-10-21 23:50 UTC (permalink / raw)
  To: Alexnader Kuleshov; +Cc: 24044

close 24044
quit

Alexnader Kuleshov <kuleshovmail@gmail.com> writes:

> Attached patch introduces make_temp_name_buf() function which will do
> this functionality and allows to avoid
> code duplication.
>
> Thank you
>
>>From c58d13c750901e9f47c99dd2466e95dabb3730a1 Mon Sep 17 00:00:00 2001
> From: Alexander Kuleshov <kuleshovmail@gmail.com>
> Date: Wed, 20 Jul 2016 18:33:55 +0600
> Subject: [PATCH] fileio.c: introduce make_temp_name_buf
>
> * src/fileio.c: New function - make_temp_name_buf. Use it in the
> make_temp_name() function.

Following recent changes to the make-temp-name and related functions,
this patch is no longer applicable.






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-21 23:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-21 10:02 bug#24044: [PATCH] fileio.c: introduce make_temp_name_buf Alexnader Kuleshov
2017-10-21 23:50 ` Noam Postavsky

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).