* Eliminate previously introduced redundant string copying.
authorDirk Herrmann <dirk@dirk-herrmanns-seiten.de>
Mon, 9 Oct 2000 09:54:28 +0000 (09:54 +0000)
committerDirk Herrmann <dirk@dirk-herrmanns-seiten.de>
Mon, 9 Oct 2000 09:54:28 +0000 (09:54 +0000)
libguile/ChangeLog
libguile/numbers.c

index 9eb8ca2..3a724bd 100644 (file)
@@ -1,3 +1,9 @@
+2000-10-09  Dirk Herrmann  <D.Herrmann@tu-bs.de>
+
+       * numbers.c (big2str):  Avoid redundant copying.
+
+       (scm_bigprint):  Use SCM_STRING_LENGTH instead of SCM_LENGTH.
+
 2000-10-06  Dirk Herrmann  <D.Herrmann@tu-bs.de>
 
        * numbers.c (big2str), read.c (scm_grow_tok_buf), strports.c
index 2092927..7e6a792 100644 (file)
@@ -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