mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Minor make-string optimization
* libguile/strings.c (STRINGBUF_SET_MUTABLE): New helper. (scm_i_string_ensure_mutable_x): Use new helper. (scm_make_string): Mark stringbuf as mutable.
This commit is contained in:
parent
2864f11d34
commit
9ee21f3e97
1 changed files with 11 additions and 3 deletions
|
@ -83,6 +83,10 @@ SCM_SYMBOL (sym_error, "error");
|
|||
#define STRINGBUF_WIDE(buf) (SCM_CELL_WORD_0(buf) & STRINGBUF_F_WIDE)
|
||||
#define STRINGBUF_MUTABLE(buf) (SCM_CELL_WORD_0(buf) & STRINGBUF_F_MUTABLE)
|
||||
|
||||
|
||||
#define STRINGBUF_SET_MUTABLE(buf) \
|
||||
SCM_SET_CELL_WORD_0 (buf, SCM_CELL_WORD_0 (buf) | STRINGBUF_F_MUTABLE)
|
||||
|
||||
#define STRINGBUF_CONTENTS(buf) ((void *) \
|
||||
SCM_CELL_OBJECT_LOC (buf, \
|
||||
STRINGBUF_HEADER_SIZE))
|
||||
|
@ -433,8 +437,7 @@ scm_i_string_ensure_mutable_x (SCM str)
|
|||
memcpy (STRINGBUF_CHARS (new_buf), STRINGBUF_CHARS (buf), len);
|
||||
}
|
||||
|
||||
SCM_SET_CELL_WORD_0 (new_buf,
|
||||
SCM_CELL_WORD_0 (new_buf) | STRINGBUF_F_MUTABLE);
|
||||
STRINGBUF_SET_MUTABLE (new_buf);
|
||||
SET_STRING_STRINGBUF (str, new_buf);
|
||||
}
|
||||
}
|
||||
|
@ -1119,7 +1122,12 @@ SCM_DEFINE (scm_make_string, "make-string", 1, 1, 0,
|
|||
"of the string are all set to @code{#\nul}.")
|
||||
#define FUNC_NAME s_scm_make_string
|
||||
{
|
||||
return scm_c_make_string (scm_to_size_t (k), chr);
|
||||
SCM ret = scm_c_make_string (scm_to_size_t (k), chr);
|
||||
/* Given that make-string is mostly used by Scheme to prepare a
|
||||
mutable string buffer, let's go ahead and mark this as mutable to
|
||||
avoid a copy when this buffer is next written to. */
|
||||
STRINGBUF_SET_MUTABLE (STRING_STRINGBUF (ret));
|
||||
return ret;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue