[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/02: 'string->symbol' avoids copying the underlying st
From: |
Ludovic Courtès |
Subject: |
[Guile-commits] 01/02: 'string->symbol' avoids copying the underlying string. |
Date: |
Mon, 7 Feb 2022 06:24:14 -0500 (EST) |
civodul pushed a commit to branch main
in repository guile.
commit 032acdeac9dfe6b407a1fcbd9f00c3e1a0dd27aa
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sat Feb 5 23:27:48 2022 +0100
'string->symbol' avoids copying the underlying string.
* libguile/strings.c (scm_i_make_symbol): Reuse NAME's stringbuf unless
it's mutable or NAME starts at a non-zero offset or has a different
length.
---
libguile/strings.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/libguile/strings.c b/libguile/strings.c
index a5b4b0386..5eebb3300 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -763,10 +763,16 @@ SCM
scm_i_make_symbol (SCM name, scm_t_bits flags, unsigned long hash)
{
SCM buf, symbol;
- size_t length = STRING_LENGTH (name);
+ size_t start, length = STRING_LENGTH (name);
- name = scm_i_substring_copy (name, 0, length);
- buf = STRING_STRINGBUF (name);
+ get_str_buf_start (&name, &buf, &start);
+ if (SCM_UNLIKELY (STRINGBUF_MUTABLE (buf)
+ || start != 0
+ || STRINGBUF_LENGTH (buf) != length))
+ {
+ name = scm_i_substring_copy (name, 0, length);
+ buf = STRING_STRINGBUF (name);
+ }
symbol = scm_words (scm_tc7_symbol | flags, 3);
SCM_SET_CELL_WORD_1 (symbol, SCM_UNPACK (buf));