From: Alexnader Kuleshov <kuleshovmail@gmail.com>
To: 24044@debbugs.gnu.org
Subject: bug#24044: [PATCH] fileio.c: introduce make_temp_name_buf
Date: Thu, 21 Jul 2016 16:02:21 +0600 [thread overview]
Message-ID: <20160721100221.GA27186@localhost> (raw)
[-- 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
next reply other threads:[~2016-07-21 10:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-21 10:02 Alexnader Kuleshov [this message]
2017-10-21 23:50 ` bug#24044: [PATCH] fileio.c: introduce make_temp_name_buf Noam Postavsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160721100221.GA27186@localhost \
--to=kuleshovmail@gmail.com \
--cc=24044@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).