-
-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String optimizations #122
base: master
Are you sure you want to change the base?
String optimizations #122
Conversation
Hello @jnyrup , Do you have any information about this one: "Concatenating a primitive without calling ToString() will box it in an object on which ToString() is then called." ? I believe, ReSharper also marks this code as Redundant. Best Regards, Jonathan Help us to support this library: Donate |
According to https://dotnetfiddle.net/s1jy96 using System;
public class Program
{
public static void Main()
{
Console.WriteLine(Boxing(1));
Console.WriteLine(NoBoxing(1));
}
private static string Boxing(int i){
return "a" + i;
}
private static string NoBoxing(int i){
return "b" + i.ToString();
}
} generates the following IL
Notice the In |
Thats true currently, but my opinion is that it will be an "ugly hack" in HAP's source code, since it should be a compiler feature, see: dotnet/roslyn#10966 |
|
ToLower[Invariant]
on a string, we can use aStringComparison
overload ofEquals
orCompare
.Substring
on a string, we can useString.Compare[Ordinal]
to perform equality checks on parts of a string.ToString()
will box it in anobject
on whichToString()
is then called.StringBuilder
we can avoid some allocations by appending each string to theStringBuilder
instead.ÌsHtml
as they were only used inside an if.