cvsuser     02/11/07 07:19:06

  Modified:    .        spf_render.c string.c
  Log:
  otpimized int_to_str
  
  Revision  Changes    Path
  1.12      +9 -24     parrot/spf_render.c
  
  Index: spf_render.c
  ===================================================================
  RCS file: /cvs/public/parrot/spf_render.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -w -r1.11 -r1.12
  --- spf_render.c      6 Nov 2002 08:52:07 -0000       1.11
  +++ spf_render.c      7 Nov 2002 15:19:05 -0000       1.12
  @@ -1,7 +1,7 @@
   /* spf_render.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: spf_render.c,v 1.11 2002/11/06 08:52:07 leo Exp $
  + *     $Id: spf_render.c,v 1.12 2002/11/07 15:19:05 leo Exp $
    *  Overview:
    *     Implements the main function that drives the Parrot_sprintf
    *     family and its utility functions.
  @@ -28,41 +28,26 @@
   uint_to_str(struct Parrot_Interp *interpreter,
               char *tc, UHUGEINTVAL num, char base, int minus)
   {
  -    int i = 0, cur2;
       char cur;
  -    STRING *out;
  +    char *tail, *p;
  +    /* the buffer must be at least as long as this */
  +    tail = p = tc + sizeof(UHUGEINTVAL)*8 + 1;
   
       do {
           cur = (char)(num % base);
  -
           if (cur < 10) {
  -            tc[i] = (char)('0' + cur);
  +            *--p = (char)('0' + cur);
           }
           else {
  -            tc[i] = (char)('a' + cur - 10);
  +            *--p = (char)('a' + cur - 10);
           }
  -
  -        i++;
       } while (num /= base);
  -
  -    cur2 = i - 1;
  -
  -    /* This fixes the problems some people have experienced
  -     * with precision--the string was being reused without
  -     * being cleared first.
  -     */
       if (minus)
  -        out = cstr2pstr("-");
  -    else
  -        out = cstr2pstr("");
  -
  -    for (i = 0; i <= cur2; i++) {
  -        string_append(interpreter, out, char2pstr(tc[cur2 - i]), 0);
  -    }
  -    return out;
  +        *--p = '-';
  +    return string_make(interpreter, p, tail - p, NULL, 0, NULL);
   }
   
  -static STRING *
  +STRING *
   int_to_str(struct Parrot_Interp *interpreter,
              char *tc, HUGEINTVAL num, char base)
   {
  
  
  
  1.110     +6 -22     parrot/string.c
  
  Index: string.c
  ===================================================================
  RCS file: /cvs/public/parrot/string.c,v
  retrieving revision 1.109
  retrieving revision 1.110
  diff -u -w -r1.109 -r1.110
  --- string.c  6 Nov 2002 08:52:07 -0000       1.109
  +++ string.c  7 Nov 2002 15:19:05 -0000       1.110
  @@ -1,7 +1,7 @@
   /* string.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: string.c,v 1.109 2002/11/06 08:52:07 leo Exp $
  + *     $Id: string.c,v 1.110 2002/11/07 15:19:05 leo Exp $
    *  Overview:
    *     This is the api definitions for the string subsystem
    *  Data Structure and Algorithms:
  @@ -634,7 +634,11 @@
       }
   
       /* do in-place i.e. make a COW string */
  +#if 1
       dest = string_set(interpreter, *d, src);
  +#else
  +    dest = make_COW_reference(interpreter, src);
  +#endif
       if (src->encoding->index == enum_encoding_singlebyte) {
           dest->strstart = (char *)dest->strstart + true_offset;
           dest->bufused = true_length;
  @@ -1066,27 +1070,7 @@
   STRING *
   string_from_int(struct Parrot_Interp * interpreter, INTVAL i) {
       char buf[128];
  -    char *ptr = &buf[127];
  -    int neg = 0;
  -
  -    if(i < 0) {
  -        neg = 1;
  -        i = -i;
  -    }
  -
  -    /* Dangerous looking but no 32/64/128/.... bit int
  -     * would approach 128 characters in the buffer.
  -     */
  -    do {
  -        *--ptr = (char)('0' + i % 10);
  -    }
  -    while(i /= 10);
  -
  -    if(neg)
  -        *--ptr = '-';
  -
  -    return string_make(interpreter, ptr, (UINTVAL)(127 - (ptr - buf)),
  -                            NULL, 0, NULL);
  +    return int_to_str(interpreter, buf, i, 10);
   }
   
   /* Stolen, with modifications, from perlnum.pmc */
  
  
  


Reply via email to