all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Mark Oteiza <mvoteiza@udel.edu>
To: 28362@debbugs.gnu.org
Subject: bug#28362: 26.0.50; [PATCH] gensym in core elisp
Date: Tue, 5 Sep 2017 13:27:33 -0400	[thread overview]
Message-ID: <20170905172733.GA10016@holos.localdomain> (raw)
In-Reply-To: <8737812hqc.fsf@holos>

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

On 05/09/17 at 01:11pm, Mark Oteiza wrote:
>I wrote a naïve gensym in C that is only about 1.5x to 2x faster than
>cl-gensym (and incompatible because of the inaccessible counter). Patch
>attached.

There was a bunch of other crap in that patch--clean one attached.


[-- Attachment #2: gensym_alloc_c.patch --]
[-- Type: text/x-diff, Size: 1622 bytes --]

diff --git a/src/alloc.c b/src/alloc.c
index 2cee646256..89372c11b5 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3632,6 +3632,32 @@ Its value is void, and its function definition and property list are nil.  */)
   return val;
 }
 
+static Lisp_Object default_gensym_prefix;
+
+DEFUN ("gensym", Fgensym, Sgensym, 0, 1, 0,
+       doc: /* Return a new uninterned symbol.
+The name is made by concatenating PREFIX with a counter value.
+PREFIX is a string and defaults to "g".
+There is no provision for resetting the counter. */)
+  (Lisp_Object prefix)
+{
+  static int gensym_counter = 0;
+
+  Lisp_Object suffix, name;
+  int len;
+  char buf[INT_STRLEN_BOUND (EMACS_INT)];
+
+  if (NILP (prefix))
+    prefix = default_gensym_prefix;
+  CHECK_STRING (prefix);
+
+  EMACS_INT count = gensym_counter++;
+  len = sprintf (buf, "%"pI"d", count);
+  suffix = make_string (buf, len);
+  name = concat2 (prefix, suffix);
+  return Fmake_symbol (name);
+}
+
 
 \f
 /***********************************************************************
@@ -7515,6 +7541,8 @@ The time is in seconds as a floating point value.  */);
   DEFVAR_INT ("gcs-done", gcs_done,
               doc: /* Accumulated number of garbage collections done.  */);
 
+  default_gensym_prefix = build_pure_c_string ("g");
+
   defsubr (&Scons);
   defsubr (&Slist);
   defsubr (&Svector);
@@ -7527,6 +7555,7 @@ The time is in seconds as a floating point value.  */);
   defsubr (&Smake_string);
   defsubr (&Smake_bool_vector);
   defsubr (&Smake_symbol);
+  defsubr (&Sgensym);
   defsubr (&Smake_marker);
   defsubr (&Smake_finalizer);
   defsubr (&Spurecopy);

  reply	other threads:[~2017-09-05 17:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-05 17:11 bug#28362: 26.0.50; [PATCH] gensym in core elisp Mark Oteiza
2017-09-05 17:27 ` Mark Oteiza [this message]
2017-09-11 20:35 ` Mark Oteiza
2017-09-12 14:39   ` Eli Zaretskii
2017-09-12 15:14     ` Mark Oteiza

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=20170905172733.GA10016@holos.localdomain \
    --to=mvoteiza@udel.edu \
    --cc=28362@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 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.