cvsuser     03/11/03 04:54:48

  Modified:    src      chartype.c string.c
  Log:
  Performance tweak to unicode is_digit and get_digit
  get_digit always returns -1 if not a digit
  string_to_num only accepts digits from one group
  
  Revision  Changes    Path
  1.17      +16 -8     parrot/src/chartype.c
  
  Index: chartype.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/chartype.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -w -r1.16 -r1.17
  --- chartype.c        23 Oct 2003 17:48:59 -0000      1.16
  +++ chartype.c        3 Nov 2003 12:54:48 -0000       1.17
  @@ -1,7 +1,7 @@
   /* chartype.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: chartype.c,v 1.16 2003/10/23 17:48:59 robert Exp $
  + *     $Id: chartype.c,v 1.17 2003/11/03 12:54:48 petergibbs Exp $
    *  Overview:
    *     This defines the string character type subsystem
    *  Data Structure and Algorithms:
  @@ -229,14 +229,18 @@
   Parrot_Int
   chartype_is_digit_map1(const CHARTYPE* type, const UINTVAL c)
   {
  -    return c >= type->digit_map->first_code
  -        && c <= type->digit_map->last_code;
  +    return c >= type->digit_map->first_code && c <= type->digit_map->last_code;
   }
   
   Parrot_Int
   chartype_get_digit_map1(const CHARTYPE* type, const UINTVAL c)
   {
  +    if (c >= type->digit_map->first_code && c <= type->digit_map->last_code)
       return c - type->digit_map->first_code + type->digit_map->first_value;
  +    else {
  +        /* XXX Should we throw an exception? */
  +        return -1;
  +    }
   }
   
   Parrot_Int
  @@ -244,8 +248,10 @@
   {
       const struct chartype_digit_map_t *map = type->digit_map;
       while (map->first_value >= 0) {
  -        if (c >= map->first_code && c <= map->last_code)
  -            return 1;
  +        if (c < map->first_code)
  +            return 0;
  +        if (c <= map->last_code)
  +            return map->last_code;
           map++;
       }
       return 0;
  @@ -256,11 +262,13 @@
   {
       const struct chartype_digit_map_t *map = type->digit_map;
       while (map->first_value >= 0) {
  -        if (c >= map->first_code && c <= map->last_code)
  +        if (c < map->first_code)
  +            break;
  +        if (c <= map->last_code)
               return c - map->first_code + map->first_value;
           map++;
       }
  -    /* TODO should we throw an exception? */
  +    /* XXX should we throw an exception? */
       return -1;
   }
   
  
  
  
  1.153     +7 -2      parrot/src/string.c
  
  Index: string.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/string.c,v
  retrieving revision 1.152
  retrieving revision 1.153
  diff -u -w -r1.152 -r1.153
  --- string.c  27 Oct 2003 15:14:35 -0000      1.152
  +++ string.c  3 Nov 2003 12:54:48 -0000       1.153
  @@ -1,7 +1,7 @@
   /* string.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: string.c,v 1.152 2003/10/27 15:14:35 leo Exp $
  + *     $Id: string.c,v 1.153 2003/11/03 12:54:48 petergibbs Exp $
    *  Overview:
    *     This is the api definitions for the string subsystem
    *  Data Structure and Algorithms:
  @@ -1350,11 +1350,16 @@
           INTVAL in_number = 0;
           FLOATVAL exponent = 0;
           INTVAL fake_exponent = 0;
  +        INTVAL digit_family = 0;
   
           while (start < end) {
               UINTVAL c = s->encoding->decode(start);
  +            INTVAL df = s->type->is_digit(s->type,c);
   
  -            if (s->type->is_digit(s->type,c)) {
  +            if (df && !digit_family)
  +                digit_family = df;
  +
  +            if (df && df == digit_family) {
                   if (in_exp) {
                       exponent = exponent * 10 + s->type->get_digit(s->type,c);
                       if (!exp_sign) {
  
  
  

Reply via email to