[Mono-list] string equals method

Slide slide.o.mix at gmail.com
Tue May 21 22:29:11 UTC 2013


You can look at the source for mono's implementation of string.Equals here

https://github.com/mono/mono/blob/master/mcs/class/corlib/System/String.cs#L69

slide


On Tue, May 21, 2013 at 3:25 PM, Edward Ned Harvey (mono) <
edward.harvey.mono at clevertrove.com> wrote:

>  Msdn says string.Equals() overrides the string == operator.****
>
> ** **
>
> Msdn also says it's an ordinal comparison, blah blah.  ** **
>
> ** **
>
> The thing I'd like to know:  Ordinal string comparison tends to be an
> expensive thing to do.  This can be skipped under certain circumstances,
> such as, if ReferenceEquals returns true, or if the two string length's are
> different.****
>
> ** **
>
> Can anybody authoritatively say, under the hood, that .Net or mono
> actually do this sort of acceleration in the string.Equals() method?****
>
> ** **
>
> public static bool operator ==( string a, string b)****
>
> {****
>
>                 if ( Object.ReferenceEquals(a,b) )****
>
>                                 return true;****
>
>                 else****
>
>                 {****
>
>                                 if ( a.Length != b.Length )****
>
>                                                 return false;****
>
>                                 else****
>
>                                 {****
>
>                                                 for ( int i=0; i<a.Length
> ; i++ )****
>
>                                                                 if ( a[i]
> != b[i] )****
>
>
> return false;****
>
>                                                 return true;****
>
>                                 }****
>
>                 }****
>
> }****
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
>


-- 
Website: http://earl-of-code.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-list/attachments/20130521/be6eca3c/attachment-0001.html>


More information about the Mono-list mailing list