dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private NumberParser.


From: Jonathan Springer <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private NumberParser.cs,1.8,1.9
Date: Sun, 02 Feb 2003 13:26:09 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private
In directory subversions:/tmp/cvs-serv19790/runtime/System/Private

Modified Files:
        NumberParser.cs 
Log Message:


Performance enhancement (reduce StringBuilder use)


Index: NumberParser.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberParser.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** NumberParser.cs     2 Feb 2003 16:39:18 -0000       1.8
--- NumberParser.cs     2 Feb 2003 18:26:07 -0000       1.9
***************
*** 1030,1062 ****
                decimal work = 0.0m;
  
                //  Parse up to the decimal
!               while (sb.Length > 0 && sb[0] >= '0' && sb[0] <= '9')
                {
!                       work *= 10;
!                       work += (uint)(sb[0] - '0');
!                       sb.Remove(0, 1);
                }
  
                //  Parse after the decimal
!               if (sb.Length > 0 
!                               && 
sb.ToString().StartsWith(nfi.NumberDecimalSeparator))
                {
!                       sb.Remove(0, nfi.NumberDecimalSeparator.Length);
  
                        decimal temp;
                        int i, j;
                        for (i = -1; 
!                                       sb.Length > 0 && sb[0] >= '0' && sb[0] 
<= '9' ; 
                                        i--)
                        {
!                               temp = (decimal)((uint)(sb[0] - '0'));
                                for (j = 0; j > i; j--) temp *= 0.1m;
                                work += temp;
-                               sb.Remove(0, 1);
                        }       
                }
  
                //  Parse after the exponent
!               if (sb.Length > 0 && (sb[0] == 'e' || sb[0] == 'E') ) 
                {
                        uint exp = 0;
--- 1030,1065 ----
                decimal work = 0.0m;
  
+               string str = sb.ToString();
+               int stridx = 0;
+ 
                //  Parse up to the decimal
!               while (stridx < str.Length 
!                               && str[stridx] >= '0' && str[stridx] <= '9')
                {
!                       work = 10 * work + (str[stridx++] - '0');
                }
  
                //  Parse after the decimal
!               if (stridx < str.Length && 
!                               
str.Substring(stridx).StartsWith(nfi.NumberDecimalSeparator))
                {
!                       stridx += nfi.NumberDecimalSeparator.Length;
  
                        decimal temp;
                        int i, j;
                        for (i = -1; 
!                                       stridx < str.Length && 
!                                       str[stridx] >= '0' && str[stridx] <= 
'9' ; 
                                        i--)
                        {
!                               temp = (decimal)((uint)(str[stridx++] - '0'));
                                for (j = 0; j > i; j--) temp *= 0.1m;
                                work += temp;
                        }       
                }
  
                //  Parse after the exponent
!               if (stridx < str.Length 
!                               && (str[stridx] == 'e' || str[stridx] == 'E') ) 
                {
                        uint exp = 0;
***************
*** 1064,1078 ****
                        decimal mult;
  
!                       sb.Remove(0, 1);
  
!                       if (sb.ToString().StartsWith(nfi.PositiveSign)) 
                        {
                                mult = 10.0m;
!                               sb.Remove(0, nfi.PositiveSign.Length);
                        } 
!                       else if (sb.ToString().StartsWith(nfi.NegativeSign)) 
                        {
                                mult = 0.1m;
!                               sb.Remove(0, nfi.NegativeSign.Length);
                        } 
                        else
--- 1067,1081 ----
                        decimal mult;
  
!                       stridx++;
  
!                       if (str.Substring(stridx).StartsWith(nfi.PositiveSign)) 
                        {
                                mult = 10.0m;
!                               stridx++;
                        } 
!                       else if 
(str.Substring(stridx).StartsWith(nfi.NegativeSign)) 
                        {
                                mult = 0.1m;
!                               stridx++;
                        } 
                        else
***************
*** 1081,1089 ****
                        }
  
!                   while (sb.Length > 0 && sb[0] >= '0' && sb[0] <= '9')
                        {
!                               exp *= 10;
!                               exp += (uint)(sb[0] - '0');
!                               sb.Remove(0, 1);
                        }
  
--- 1084,1091 ----
                        }
  
!                   while (stridx < str.Length 
!                                       && str[stridx] >= '0' && str[stridx] <= 
'9')
                        {
!                               exp = 10 * exp + (uint)(str[stridx++] - '0');
                        }
  
***************
*** 1091,1095 ****
                }
  
!               if (sb.Length > 0)
                {
                        //  Oops.  Throw a "junk found" exception.
--- 1093,1097 ----
                }
  
!               if (stridx < str.Length)
                {
                        //  Oops.  Throw a "junk found" exception.
***************
*** 1120,1160 ****
                bool negative = StripSign(sb, nfi);
  
                //  Parse up to the decimal
                double work = 0.0d;
!               while (sb.Length > 0 && sb[0] >= '0' && sb[0] <= '9')
                {
!                       work *= 10;
!                       work += (uint)(sb[0] - '0');
!                       sb.Remove(0, 1);
                }
  
                //  Parse after the decimal
!               if (sb.Length > 0 
!                               && 
sb.ToString().StartsWith(nfi.NumberDecimalSeparator))
                {
!                       sb.Remove(0, nfi.NumberDecimalSeparator.Length);
!                       for (int i = -1; 
!                                       sb.Length > 0 && sb[0] >= '0' && sb[0] 
<= '9' ; 
!                                       i--)
                        {
!                               work += (uint)(sb[0] - '0') * Math.Pow(10, i);
!                               sb.Remove(0, 1);
                        }       
                }
  
                //  Parse after the exponent
!               if (sb.Length > 0 && (sb[0] == 'e' || sb[0] == 'E') ) 
                {
                        uint exponent = 0;
                        bool negExponent = false;
!                       sb.Remove(0, 1);
!                       if (sb.ToString().StartsWith(nfi.PositiveSign)) 
                        {
!                               sb.Remove(0, nfi.PositiveSign.Length);
                        } 
!                       else if (sb.ToString().StartsWith(nfi.NegativeSign)) 
                        {
                                negExponent = true;
!                               sb.Remove(0, nfi.NegativeSign.Length);
                        } 
                        /*  --- Removed in response to bug #2222
--- 1122,1166 ----
                bool negative = StripSign(sb, nfi);
  
+               string str = sb.ToString();
+               int stridx = 0;
+ 
                //  Parse up to the decimal
                double work = 0.0d;
! 
!               while (stridx < str.Length 
!                               && str[stridx] >= '0' && str[stridx] <= '9')
                {
!                       work = work * 10.0d + (uint)(str[stridx++] - '0');
                }
  
                //  Parse after the decimal
!               if (stridx < str.Length && 
!                               
str.Substring(stridx).StartsWith(nfi.NumberDecimalSeparator))
                {
!                       stridx += nfi.NumberDecimalSeparator.Length;
!                       for (double mult = 0.1d;
!                                       stridx < str.Length && 
!                                       str[stridx] >= '0' && str[stridx] <= 
'9';
!                                       mult /= 10.0d)
                        {
!                               work += (uint)(str[stridx++] - '0') * mult;
                        }       
                }
  
                //  Parse after the exponent
!               if (stridx < str.Length 
!                               && (str[stridx] == 'e' || str[stridx] == 'E') ) 
                {
                        uint exponent = 0;
                        bool negExponent = false;
!                       stridx++;
!                       if (str.Substring(stridx).StartsWith(nfi.PositiveSign)) 
                        {
!                               stridx++;
                        } 
!                       else if 
(str.Substring(stridx).StartsWith(nfi.NegativeSign)) 
                        {
                                negExponent = true;
!                               stridx++;
                        } 
                        /*  --- Removed in response to bug #2222
***************
*** 1166,1174 ****
                        */
  
!                   while (sb.Length > 0 && sb[0] >= '0' && sb[0] <= '9')
                        {
!                               exponent *= 10;
!                               exponent += (uint)(sb[0] - '0');
!                               sb.Remove(0, 1);
                        }
  
--- 1172,1179 ----
                        */
  
!                   while (stridx < str.Length && 
!                                       str[stridx] >= '0' && str[stridx] <= 
'9')
                        {
!                               exponent = 10 * exponent + (uint)(str[stridx++] 
- '0');
                        }
  
***************
*** 1176,1180 ****
                }
  
!               if (sb.Length > 0)
                {
                        //  Oops.  Throw a "junk found" exception.
--- 1181,1185 ----
                }
  
!               if (stridx < str.Length)
                {
                        //  Oops.  Throw a "junk found" exception.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]