WiseTechGlobal / WTG.Analyzers

Analyzers from WiseTech Global to enforce our styles, behaviours, and prevent common mistakes.
Other
16 stars 3 forks source link

Analyser to warn against wasteful string.Split calls #161

Open yaakov-h opened 2 years ago

yaakov-h commented 2 years ago

i.e.:

"abc def ghi jkl".Split(' ')[0]

No point allocating substrings (plus the containing array) that all get immediately discarded.

yaakov-h commented 2 years ago

This one might need some flow analysis:

var bits = key.Split('|');
return bits[0];

Unless we just want to ban string.Split entirely, but that idea doesn't sit well with me.