summaryrefslogtreecommitdiff
path: root/libguile/symbols.c
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2011-03-06 21:47:48 +0100
committerLudovic Courtès <ludo@gnu.org>2011-03-06 23:05:00 +0100
commitceed7709becfe64eaaff54aa445b09d1882d589d (patch)
treea715251a8cb6d7ead67aa102846ba3717f5f6fe8 /libguile/symbols.c
parentd8f1c2162c3a34f4bc29ee7f6fab426e6e11e36a (diff)
downloadguile-ceed7709becfe64eaaff54aa445b09d1882d589d.tar.gz
Slightly optimize `gensym'.
* libguile/symbols.c (default_gensym_prefix): New variable. (scm_gensym): Use it. Use `scm_from_latin1_stringn' instead of `scm_from_locale_stringn'. (scm_init_symbols): Initialize DEFAULT_GENSYM_PREFIX.
Diffstat (limited to 'libguile/symbols.c')
-rw-r--r--libguile/symbols.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/libguile/symbols.c b/libguile/symbols.c
index b9d41b0e2..2a1b46dce 100644
--- a/libguile/symbols.c
+++ b/libguile/symbols.c
@@ -1,5 +1,6 @@
-/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2003, 2004, 2006, 2009 Free Software Foundation, Inc.
- *
+/* Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2003, 2004,
+ * 2006, 2009, 2011 Free Software Foundation, Inc.
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3 of
@@ -341,6 +342,9 @@ SCM_DEFINE (scm_string_ci_to_symbol, "string-ci->symbol", 1, 0, 0,
}
#undef FUNC_NAME
+/* The default prefix for `gensym'd symbols. */
+static SCM default_gensym_prefix;
+
#define MAX_PREFIX_LENGTH 30
SCM_DEFINE (scm_gensym, "gensym", 0, 1, 0,
@@ -359,15 +363,15 @@ SCM_DEFINE (scm_gensym, "gensym", 0, 1, 0,
char buf[SCM_INTBUFLEN];
if (SCM_UNBNDP (prefix))
- prefix = scm_from_locale_string (" g");
-
+ prefix = default_gensym_prefix;
+
/* mutex in case another thread looks and incs at the exact same moment */
scm_i_scm_pthread_mutex_lock (&scm_i_misc_mutex);
n = gensym_counter++;
scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
n_digits = scm_iint2str (n, 10, buf);
- suffix = scm_from_locale_stringn (buf, n_digits);
+ suffix = scm_from_latin1_stringn (buf, n_digits);
name = scm_string_append (scm_list_2 (prefix, suffix));
return scm_string_to_symbol (name);
}
@@ -506,6 +510,8 @@ void
scm_init_symbols ()
{
#include "libguile/symbols.x"
+
+ default_gensym_prefix = scm_from_latin1_string (" g");
}
/*