summaryrefslogtreecommitdiff
path: root/libguile/strings.c
diff options
context:
space:
mode:
authorMichael Gran <spk121@yahoo.com>2009-08-19 21:26:11 -0700
committerMichael Gran <spk121@yahoo.com>2009-08-19 22:15:32 -0700
commit9aa27c1a30c222ab668d8d6fc7aa7ad815282594 (patch)
tree0c832eb88de991dae3deb75c767338d589dc8976 /libguile/strings.c
parentf8ba2bb9117d75c93503fe3dde9054f5ff92c51c (diff)
downloadguile-9aa27c1a30c222ab668d8d6fc7aa7ad815282594.tar.gz
Try to optimize scm_string for speed
* libguile/strings.c (scm_string): optimize for speed
Diffstat (limited to 'libguile/strings.c')
-rw-r--r--libguile/strings.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/libguile/strings.c b/libguile/strings.c
index 7ae100d8c..62758617f 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -1008,11 +1008,12 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1,
"@var{chrs}.")
#define FUNC_NAME s_scm_string
{
- SCM result;
+ SCM result = SCM_BOOL_F;
SCM rest;
size_t len;
size_t p = 0;
long i;
+ int wide = 0;
/* Verify that this is a list of chars. */
i = scm_ilength (chrs);
@@ -1025,6 +1026,8 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1,
{
SCM elt = SCM_CAR (rest);
SCM_VALIDATE_CHAR (SCM_ARGn, elt);
+ if (SCM_CHAR (elt) > 0xFF)
+ wide = 1;
rest = SCM_CDR (rest);
len--;
scm_remember_upto_here_1 (elt);
@@ -1034,16 +1037,35 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1,
len = (size_t) i;
rest = chrs;
- result = scm_i_make_string (len, NULL);
- result = scm_i_string_start_writing (result);
- while (len > 0 && scm_is_pair (rest))
+ if (wide == 0)
{
- SCM elt = SCM_CAR (rest);
- scm_i_string_set_x (result, p, SCM_CHAR (elt));
- p++;
- rest = SCM_CDR (rest);
- len--;
- scm_remember_upto_here_1 (elt);
+ result = scm_i_make_string (len, NULL);
+ result = scm_i_string_start_writing (result);
+ char *buf = scm_i_string_writable_chars (result);
+ while (len > 0 && scm_is_pair (rest))
+ {
+ SCM elt = SCM_CAR (rest);
+ buf[p] = (unsigned char) SCM_CHAR (elt);
+ p++;
+ rest = SCM_CDR (rest);
+ len--;
+ scm_remember_upto_here_1 (elt);
+ }
+ }
+ else
+ {
+ result = scm_i_make_wide_string (len, NULL);
+ result = scm_i_string_start_writing (result);
+ scm_t_wchar *buf = scm_i_string_writable_wide_chars (result);
+ while (len > 0 && scm_is_pair (rest))
+ {
+ SCM elt = SCM_CAR (rest);
+ buf[p] = SCM_CHAR (elt);
+ p++;
+ rest = SCM_CDR (rest);
+ len--;
+ scm_remember_upto_here_1 (elt);
+ }
}
scm_i_string_stop_writing ();