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

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

[dotgnu-pnet-commits] pnetlib ChangeLog runtime/System/Private/Number...


From: Heiko Weiss
Subject: [dotgnu-pnet-commits] pnetlib ChangeLog runtime/System/Private/Number...
Date: Thu, 10 May 2007 10:38:59 +0000

CVSROOT:        /sources/dotgnu-pnet
Module name:    pnetlib
Changes by:     Heiko Weiss <brubbel>   07/05/10 10:38:58

Modified files:
        .              : ChangeLog 
        runtime/System/Private/NumberFormat: Formatter.cs 
                                             GeneralFormatter.cs 
                                             FixedPointFormatter.cs 

Log message:
        optimized performance.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnetlib/ChangeLog?cvsroot=dotgnu-pnet&r1=1.2498&r2=1.2499
http://cvs.savannah.gnu.org/viewcvs/pnetlib/runtime/System/Private/NumberFormat/Formatter.cs?cvsroot=dotgnu-pnet&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/pnetlib/runtime/System/Private/NumberFormat/GeneralFormatter.cs?cvsroot=dotgnu-pnet&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/pnetlib/runtime/System/Private/NumberFormat/FixedPointFormatter.cs?cvsroot=dotgnu-pnet&r1=1.3&r2=1.4

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/dotgnu-pnet/pnetlib/ChangeLog,v
retrieving revision 1.2498
retrieving revision 1.2499
diff -u -b -r1.2498 -r1.2499
--- ChangeLog   23 Apr 2007 19:21:31 -0000      1.2498
+++ ChangeLog   10 May 2007 10:38:58 -0000      1.2499
@@ -1,3 +1,10 @@
+2007-05-10  Heiko Weiss <address@hidden>
+
+       * runtime/System/Private/NumberFormat/Formatter.cs,
+               runtime/System/Private/NumberFormat/GeneralFormatter.cs,
+               runtime/System/Private/NumberFormat/FixedPointFormatter.cs:
+       optimized performance.
+
 2007-04-23  Radek Polak  <address@hidden>
 
        * pnetlib/System.Windows.Forms/MainMenu.cs: Handle repaint more

Index: runtime/System/Private/NumberFormat/Formatter.cs
===================================================================
RCS file: 
/sources/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/Formatter.cs,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- runtime/System/Private/NumberFormat/Formatter.cs    1 Sep 2006 06:30:33 
-0000       1.15
+++ runtime/System/Private/NumberFormat/Formatter.cs    10 May 2007 10:38:58 
-0000      1.16
@@ -74,18 +74,18 @@
 
        static protected bool IsSignedInt(Object o)
        {
-               return (o is SByte || o is Int16 || o is Int32 || o is Int64);
+               return ( o is Int32 || o is Int16 || o is Int64 || o is SByte  
);
        }
        
        static protected bool IsUnsignedInt(Object o)
        {
-               return (o is Byte || o is UInt16 || o is UInt32 || o is UInt64);
+               return (o is UInt32 ||  o is UInt16 || o is UInt64 || o is Byte 
);
        }
        
 #if CONFIG_EXTENDED_NUMERICS
        static protected bool IsFloat(Object o)
        {
-               return (o is Single || o is Double);
+               return (o is Double || o is Single );
        }
        
        static protected bool IsDecimal(Object o)
@@ -299,9 +299,11 @@
                string ret;
 
                //  Type validation
-               if (IsSignedInt(o) && (OToLong(o) < 0) )
+               if (IsSignedInt(o) )
                {
-                       ulong value=(ulong) -OToLong(o);
+                       long  lvalue = OToLong(o);
+                       if( lvalue < 0 ) {
+                               ulong value=(ulong) -lvalue;
 
                        if(value==0)
                        {
@@ -313,10 +315,15 @@
                                ret = "-" + Formatter.FormatInteger(value);
                        }
                }
-               else if (IsSignedInt(o) || IsUnsignedInt(o))
+                       else {
+                               ret = Formatter.FormatInteger(OToUlong(o));
+                       }
+               }
+               else if (IsUnsignedInt(o))
                {
                        ret = Formatter.FormatInteger(OToUlong(o));
                }
+
 #if CONFIG_EXTENDED_NUMERICS
                else if (IsDecimal(o))
                {
@@ -352,7 +359,8 @@
                        {
                                return NumberFormatInfo(provider).NaNSymbol;
                        }
-                       else if (Double.IsPositiveInfinity(val))
+                       else if( Double.IsInfinity(val) ) {
+                               if (Double.IsPositiveInfinity(val))
                        {
                                return 
NumberFormatInfo(provider).PositiveInfinitySymbol;
                        }
@@ -360,6 +368,7 @@
                        {
                                return 
NumberFormatInfo(provider).NegativeInfinitySymbol;
                        }
+                       }
                        else {
                                // do not round here, is done in 
Formatter.FormatFloat
                                if (val < 0) ret = "-" + Formatter.FormatFloat( 
-val, precision );
@@ -383,7 +392,7 @@
                
                if (value == 0) return ".";
 
-               StringBuilder ret = new StringBuilder(".");
+               StringBuilder ret = new StringBuilder(".", 30 );
                ulong work = value;
 
                while (work > 0) {
@@ -477,7 +486,7 @@
                //  Build a numeric representation, sans decimal point.
                //
                StringBuilder sb = 
-                       new 
StringBuilder(FormatInteger((ulong)Math.Floor(work)));
+                       new 
StringBuilder(FormatInteger((ulong)Math.Floor(work)), 30 );
                sb.Remove(sb.Length-1, 1);    // Ditch the trailing decimal 
point
 
                if (sb.Length > precision + exponent + 1)
@@ -567,8 +576,9 @@
                // handle empty format
                if(format.Length == 0)
                {
-                       //return new CustomFormatter(format);
-                       return new GeneralFormatter(-1, 'G');
+                       ret = new GeneralFormatter(-1, 'G');
+                       formats[format] = ret;
+                       return ret;
                }
 
                //  Search for cached formats
@@ -577,12 +587,15 @@
                        return (Formatter) formats[format];
                }
 
+
                // Validate the format.  
                // It should be of the form 'X', 'X9', or 'X99'.
                // If it's not, return a CustomFormatter.
                if (validformats.IndexOf(format[0]) == -1 || format.Length > 3)
                {
-                       return new CustomFormatter(format);
+                       ret = new CustomFormatter(format);
+                       formats[format] = ret;
+                       return ret;
                }
 
                try 
@@ -592,7 +605,9 @@
                }
                catch (FormatException)
                {
-                       return new CustomFormatter(format);
+                       ret = new CustomFormatter(format);
+                       formats[format] = ret;
+                       return ret;
                }
                
                switch(format[0])       // There's always a yucky switch 
somewhere

Index: runtime/System/Private/NumberFormat/GeneralFormatter.cs
===================================================================
RCS file: 
/sources/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/GeneralFormatter.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- runtime/System/Private/NumberFormat/GeneralFormatter.cs     13 Apr 2006 
15:18:08 -0000      1.9
+++ runtime/System/Private/NumberFormat/GeneralFormatter.cs     10 May 2007 
10:38:58 -0000      1.10
@@ -64,21 +64,21 @@
 
        private string StripTrail(string s, IFormatProvider provider)
        {
-               StringBuilder sb = new StringBuilder(s);
                String ds = NumberFormatInfo(provider).NumberDecimalSeparator;
 
                // Strip unnecessary trailing zeroes and point
-               if (sb.ToString().IndexOf(ds) >= 0)
+               if ( s.IndexOf(ds) >= 0)
                {
+                       StringBuilder sb = new StringBuilder(s);
                        while (sb[sb.Length - 1] == '0') 
sb.Remove(sb.Length-1,1);
                        if (sb.ToString().IndexOf(ds) == sb.Length - ds.Length)
                        {
                                sb.Remove(sb.Length-ds.Length, ds.Length);
                        }
-               }
-
                return sb.ToString();
        }
+               return s;
+       }
 
        public override string Format(Object o, IFormatProvider provider)
        {
@@ -94,14 +94,15 @@
                }
 
 #if CONFIG_EXTENDED_NUMERICS
-               if (OToDouble(o) == 0.0d) 
+               double val = OToDouble(o);
+               if ( val == 0.0) 
                {
                        exponent = 0;
                }
                else
                {
                        //exponent = (int) 
Math.Floor(Math.Log10(Math.Abs(OToDouble(o))));
-                       exponent = Formatter.GetExponent( OToDouble(o) );
+                       exponent = Formatter.GetExponent( val );
                }
 #else
                // Determine the exponent without using floating-point.
@@ -140,7 +141,7 @@
                        if (exponent < precision)
                        {
                                return StripTrail(
-                                                       new 
FixedPointFormatter(0).Format(o, provider),
+                                                       
FixedPointFormatter.Format(o, 0, provider),
                                                        provider);
 
                        }
@@ -154,7 +155,7 @@
                if (exponent >= -4 && exponent < precision)
                {
                        return StripTrail(
-                                       new 
FixedPointFormatter(precision).Format(o, provider),
+                                       FixedPointFormatter.Format(o, 
precision, provider),
                                        provider);
                }
                else

Index: runtime/System/Private/NumberFormat/FixedPointFormatter.cs
===================================================================
RCS file: 
/sources/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/FixedPointFormatter.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- runtime/System/Private/NumberFormat/FixedPointFormatter.cs  14 Apr 2003 
06:04:27 -0000      1.3
+++ runtime/System/Private/NumberFormat/FixedPointFormatter.cs  10 May 2007 
10:38:58 -0000      1.4
@@ -33,12 +33,8 @@
                this.precision = precision;
        }
 
-       public override string Format(Object o, IFormatProvider provider)
+       internal static string Format(Object o, int precision, IFormatProvider 
provider)
        {
-               //  Calculate precision
-               int precision = (this.precision == -1) ?
-                       NumberFormatInfo(provider).NumberDecimalDigits : 
this.precision;
-
                //  Get string
                string rawnumber = FormatAnyRound(o, precision, provider);
                StringBuilder ret = new StringBuilder();
@@ -68,6 +64,16 @@
 
                return ret.ToString();
        }               
+
+
+       public override string Format(Object o, IFormatProvider provider)
+       {
+               //  Calculate precision
+               int precision = (this.precision == -1) ?
+                       NumberFormatInfo(provider).NumberDecimalDigits : 
this.precision;
+
+               return Format( o, precision, provider );
+       }               
 } // class FixedPointFormatter
 
 } // namespace System.Private.NumberFormat




reply via email to

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