From ceed7709becfe64eaaff54aa445b09d1882d589d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 6 Mar 2011 21:47:48 +0100 Subject: [PATCH] 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. --- libguile/symbols.c | 16 +++++++++++----- 1 file 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"); } /*