all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alexander Kuleshov <kuleshovmail@gmail.com>
To: emacs-devel@gnu.org
Subject: [PATCH] fileio.c: introduce make_temp_name_buf
Date: Wed, 20 Jul 2016 18:44:00 +0600	[thread overview]
Message-ID: <CANCZXo5oVvJC2fMFX_eX9s2yM+7Vy-H79k8bRuYo5Zivw0Y-Dg@mail.gmail.com> (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/x-patch, 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


             reply	other threads:[~2016-07-20 12:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-20 12:44 Alexander Kuleshov [this message]
2016-07-24 19:28 ` [PATCH] fileio.c: introduce make_temp_name_buf Alan Third
2016-07-24 20:01   ` Alan Third

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANCZXo5oVvJC2fMFX_eX9s2yM+7Vy-H79k8bRuYo5Zivw0Y-Dg@mail.gmail.com \
    --to=kuleshovmail@gmail.com \
    --cc=emacs-devel@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.