From aa3188a7d96a35546b9c14647da926a013570f4e Mon Sep 17 00:00:00 2001 From: Dirk Herrmann Date: Mon, 9 Oct 2000 09:54:28 +0000 Subject: [PATCH] * Eliminate previously introduced redundant string copying. --- libguile/ChangeLog | 6 ++++++ libguile/numbers.c | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 9eb8ca241..3a724bda7 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,9 @@ +2000-10-09 Dirk Herrmann + + * numbers.c (big2str): Avoid redundant copying. + + (scm_bigprint): Use SCM_STRING_LENGTH instead of SCM_LENGTH. + 2000-10-06 Dirk Herrmann * numbers.c (big2str), read.c (scm_grow_tok_buf), strports.c diff --git a/libguile/numbers.c b/libguile/numbers.c index 209292740..7e6a79281 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -2175,7 +2175,6 @@ big2str (SCM b, unsigned int radix) : (SCM_BITSPERDIG * i) + 2; scm_sizet k = 0; scm_sizet radct = 0; - scm_sizet ch; /* jeh */ SCM_BIGDIG radpow = 1, radmod = 0; SCM ss = scm_makstr ((long) j, 0); char *s = SCM_STRING_CHARS (ss), c; @@ -2184,7 +2183,6 @@ big2str (SCM b, unsigned int radix) radpow *= radix; radct++; } - s[0] = SCM_BIGSIGN (b) ? '-' : '+'; while ((i || radmod) && j) { if (k == 0) @@ -2199,13 +2197,15 @@ big2str (SCM b, unsigned int radix) k--; s[--j] = c < 10 ? c + '0' : c + 'a' - 10; } - ch = s[0] == '-' ? 1 : 0; /* jeh */ - if (ch < j) - { /* jeh */ - for (i = j; j < SCM_LENGTH (ss); j++) - s[ch + j - i] = s[j]; /* jeh */ - ss = scm_substring (ss, SCM_INUM0, - SCM_MAKINUM (ch + SCM_STRING_LENGTH (ss) - i)); + + if (SCM_BIGSIGN (b)) + s[--j] = '-'; + + if (j > 0) + { + /* The pre-reserved string length was too large. */ + unsigned long int length = SCM_STRING_LENGTH (ss); + ss = scm_substring (ss, SCM_MAKINUM (j), SCM_MAKINUM (length)); } return scm_return_first (ss, t); @@ -2270,7 +2270,7 @@ scm_bigprint (SCM exp, SCM port, scm_print_state *pstate) { #ifdef SCM_BIGDIG exp = big2str (exp, (unsigned int) 10); - scm_lfwrite (SCM_STRING_CHARS (exp), (scm_sizet) SCM_LENGTH (exp), port); + scm_lfwrite (SCM_STRING_CHARS (exp), (scm_sizet) SCM_STRING_LENGTH (exp), port); #else scm_ipruk ("bignum", exp, port); #endif