mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-05 06:50:21 +02:00
i18n: Avoid needless heap allocation.
* libguile/i18n.c (SCM_STRING_TO_U32_BUF): Allocate buffers on the stack rather on the heap. (SCM_U32_BUF_FREE): Remove. Callers updated.
This commit is contained in:
parent
12f0c3e547
commit
df047aa2b1
1 changed files with 21 additions and 30 deletions
|
@ -727,13 +727,16 @@ SCM_DEFINE (scm_locale_p, "locale?", 1, 0, 0,
|
|||
http://download.plt-scheme.org/chronology/mzmr200alpha14.html . */
|
||||
|
||||
#define SCM_STRING_TO_U32_BUF(s1, c_s1) \
|
||||
do { \
|
||||
do \
|
||||
{ \
|
||||
if (scm_i_is_narrow_string (s1)) \
|
||||
{ \
|
||||
size_t i, len; \
|
||||
const char *buf = scm_i_string_chars (s1); \
|
||||
\
|
||||
len = scm_i_string_length (s1); \
|
||||
c_s1 = (scm_t_wchar *) scm_malloc (sizeof (scm_t_wchar) * (len + 1)); \
|
||||
c_s1 = (scm_t_wchar *) alloca (sizeof (scm_t_wchar) * (len + 1)); \
|
||||
\
|
||||
for (i = 0; i < len; i ++) \
|
||||
c_s1[i] = (unsigned char ) buf[i]; \
|
||||
c_s1[len] = 0; \
|
||||
|
@ -742,16 +745,10 @@ SCM_DEFINE (scm_locale_p, "locale?", 1, 0, 0,
|
|||
c_s1 = (scm_t_wchar *) scm_i_string_wide_chars (s1); \
|
||||
} while (0)
|
||||
|
||||
#define SCM_U32_BUF_FREE(s1, c_s1) \
|
||||
do { \
|
||||
if (scm_i_is_narrow_string (s1)) \
|
||||
free (c_s1); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Compare u32 strings according to the LOCALE. Returns a negative
|
||||
value if S1 compares smaller than S2, a positive value if S1
|
||||
compares larger than S2, or 0 if they compare equal. */
|
||||
/* Compare UTF-32 strings according to LOCALE. Returns a negative value if
|
||||
S1 compares smaller than S2, a positive value if S1 compares larger than
|
||||
S2, or 0 if they compare equal. */
|
||||
static inline int
|
||||
compare_u32_strings (SCM s1, SCM s2, SCM locale, const char *func_name)
|
||||
#define FUNC_NAME func_name
|
||||
|
@ -772,9 +769,6 @@ compare_u32_strings (SCM s1, SCM s2, SCM locale, const char *func_name)
|
|||
result = u32_strcmp ((const scm_t_uint32 *) c_s1,
|
||||
(const scm_t_uint32 *) c_s2);
|
||||
|
||||
SCM_U32_BUF_FREE (s1, c_s1);
|
||||
SCM_U32_BUF_FREE (s2, c_s2);
|
||||
|
||||
scm_remember_upto_here_2 (s1, s2);
|
||||
scm_remember_upto_here (locale);
|
||||
return result;
|
||||
|
@ -830,9 +824,6 @@ compare_u32_strings_ci (SCM s1, SCM s2, SCM locale, const char *func_name)
|
|||
scm_syserror (func_name);
|
||||
}
|
||||
|
||||
SCM_U32_BUF_FREE (s1, c_s1);
|
||||
SCM_U32_BUF_FREE (s2, c_s2);
|
||||
|
||||
scm_remember_upto_here_2 (s1, s2);
|
||||
scm_remember_upto_here (locale);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue