提交 c4496f78 编写于 作者: J Jason Malinowski

Reduce memory allocations in NamingStyle.Capitalize/DecapitalizeFirstLetter

上级 f45e1654
......@@ -88,14 +88,38 @@ private IEnumerable<string> ApplyCapitalization(IEnumerable<string> words)
private string CapitalizeFirstLetter(string word)
{
if (word.Length == 0)
{
return word;
}
if (char.IsUpper(word[0]))
{
return word;
}
var chars = word.ToCharArray();
return new string(chars.Take(1).Select(c => char.ToUpper(c)).Concat(chars.Skip(1)).ToArray());
chars[0] = char.ToUpper(chars[0]);
return new string(chars);
}
private string DecapitalizeFirstLetter(string word)
{
if (word.Length == 0)
{
return word;
}
if (char.IsLower(word[0]))
{
return word;
}
var chars = word.ToCharArray();
return new string(chars.Take(1).Select(c => char.ToLower(c)).Concat(chars.Skip(1)).ToArray());
chars[0] = char.ToLower(chars[0]);
return new string(chars);
}
public bool IsNameCompliant(string name, out string failureReason)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册