[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [DotGNU]fxcop
From: |
Rhys Weatherley |
Subject: |
Re: [DotGNU]fxcop |
Date: |
Sat, 1 May 2004 06:51:35 +1000 |
User-agent: |
KMail/1.4.3 |
On Friday 30 April 2004 10:59 pm, Miroslaw Dobrzanski-Neumann wrote:
> thus a == string.Empty is not an option
> how about this replacement:
>
> if (a != null && a.Length == 0)
This will be relatively efficient when compiled with "cscc", but other C#
compilers will generate bad code for this too as they will call an overloaded
operator to do the initial null check. You'd gain nothing over the original
'if (a == "")'. To be *really* efficient, you have to do the following:
if (((Object)a) != null && a.Length == 0)
This avoids the overloaded operator, but now it is getting messy. It is worth
asking whether you are making the code unreadable for the sake of
performance. Perhaps it would be better to change the order of the
surrounding algorithm so that you are doing less string comparisons in the
first place?
Was there a particular place in the code where you noticed this type of check
causing performance problems? All systems spend 80% of their time in 20% of
the code, so if the string checks aren't in that 20%, then there's no point
making the comparison code messy.
Just because a lint program says something is bad doesn't mean that it is
always bad.
Cheers,
Rhys.