[Mono-dev] Int32.CompareTo() enhancement

Zoltan Varga vargaz at gmail.com
Thu Nov 22 16:25:03 EST 2007


Hi,

 This looks ok to check in, altough the int xv = assignment is no longer needed.

         Zoltan

On Nov 22, 2007 10:05 PM, Alan McGovern <alan.mcgovern at gmail.com> wrote:
> I was just looking at the source of int32, and i noticed that there was room
> for improvement in the implementation of CompareTo.
>
> This implementation is approx 33% faster than the existing one. Is this ok
> to commit? I can write the changelog and commit myself if i get the
> go-ahead:
>
> Index: Int32.cs
> ===================================================================
> --- Int32.cs    (revision 90185)
> +++ Int32.cs    (working copy)
> @@ -57,12 +57,7 @@
>                                 throw new ArgumentException ( Locale.GetText
> ("Value is not a System.Int32"));
>
>                         int xv = (int) v;
> -                       if (m_value == xv)
> -                               return 0;
> -                       if (m_value > xv)
> -                               return 1;
> -                       else
> -                               return -1;
> +                       return m_value - v;
>                 }
>
>                 public override bool Equals (object o)
> @@ -81,12 +76,7 @@
>  #if NET_2_0
>                 public int CompareTo (int value)
>                 {
> -                       if (m_value == value)
> -                               return 0;
> -                       if (m_value > value)
> -                               return 1;
> -                       else
> -                               return -1;
> +                       return m_value - value;
>                 }
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>



More information about the Mono-devel-list mailing list