Title: RE: [Mono-dev] DataTable Select string comparison patch

Hi Jaroslaw,

>>  1. If one object is string = "5 " and the second object is Int32 = 5. Will
>> the objects be equal?
> No, they won't even go into the "if" because o1 is string, but o2 is not string
That's right, but the question is what happens in MS .Net?
>>  2. What if a case insensitive comparison should be done, but the objects
>> are not strings? (May be type conversion should be done before the test 'o1
>> is string').
>Here we have two problems. One is i don't know what object can be case
> sensitive or case insensitive if this object is not a string.  Numbers
> don't differ lowcase or hicase, date objects will be equal/different
> whenever we compare them after converting to string and making
> tolower. And some custom objects can override CompareTo method.
> Second problem is I didn't do the ToLower conversion (I'm not the
> author of caseInsensitive comparation). I only added the TrimEnd to
> existing patch which contained the ToLower method. I have put my patch
> inside existing because I didn't want to do the "if (o is string )"
> and casting object to string twice. And yes, before patch, a
> caseSensitive test was done also only for strings.
You are absolutely correct, the code was not shining before. But since the fixes are not complex, it looks better to fix it once instead of patch on patch approach. And the interesting question arises when one object is string and the second isn't (like in previous question). What rules apply?

> >  3. Trimming + converting to low case are very expensive operations. Can you
> > rewrite your patch with respective String.Compare call? You may count spaces
> > at the end of each string and thus eliminate both trimming and case
> > lowering.
> Well, the ToLower thing was there before I started to do my
> modifications, so why noone sugested this earlier :) ?
> However I agree with You, so here is patch with String.Compare.
> But I'm not going to do trimEnd myself. Counting spaces is meaningless
> because if strings will have different length they will be different
> anyway. And if I want to omit last spaces I'll have to check if they
> are real last spaces and not just 3 spaces before next letter, so
> Instead of nice trimEnd we'll have a loop inside comparison. In my
> opinion this would take longer.
First, it's not meaningless because 'aaa' < 'bb' < 'ccc'. So unless you return boolean, it's not enough to compare by size. Second, loops are very cheap compared to potential object creation and don't take too much space:
while (count1 > 0 && Char.IsWhiteSpace(s1[count1 - 1])) count1--;

And the last thing, the DataTable.Locale should be taken into account.

Regards,
Kosta

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to