Merge pull request #3659 from Bond-009/stringbuilder

Optimize StringBuilder.Append calls
This commit is contained in:
Joshua M. Boniface 2020-07-23 18:08:09 -04:00 committed by GitHub
commit 8960d6256f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 15 deletions

View File

@ -152,11 +152,15 @@ namespace Emby.Dlna.Eventing
builder.Append("<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">"); builder.Append("<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">");
foreach (var key in stateVariables.Keys) foreach (var key in stateVariables.Keys)
{ {
builder.Append("<e:property>"); builder.Append("<e:property>")
builder.Append("<" + key + ">"); .Append('<')
builder.Append(stateVariables[key]); .Append(key)
builder.Append("</" + key + ">"); .Append('>')
builder.Append("</e:property>"); .Append(stateVariables[key])
.Append("</")
.Append(key)
.Append('>')
.Append("</e:property>");
} }
builder.Append("</e:propertyset>"); builder.Append("</e:propertyset>");

View File

@ -1110,7 +1110,8 @@ namespace Emby.Server.Implementations.Data
continue; continue;
} }
str.Append(ToValueString(i) + "|"); str.Append(ToValueString(i))
.Append('|');
} }
str.Length -= 1; // Remove last | str.Length -= 1; // Remove last |
@ -2471,7 +2472,7 @@ namespace Emby.Server.Implementations.Data
var item = query.SimilarTo; var item = query.SimilarTo;
var builder = new StringBuilder(); var builder = new StringBuilder();
builder.Append("("); builder.Append('(');
if (string.IsNullOrEmpty(item.OfficialRating)) if (string.IsNullOrEmpty(item.OfficialRating))
{ {
@ -2509,7 +2510,7 @@ namespace Emby.Server.Implementations.Data
if (!string.IsNullOrEmpty(query.SearchTerm)) if (!string.IsNullOrEmpty(query.SearchTerm))
{ {
var builder = new StringBuilder(); var builder = new StringBuilder();
builder.Append("("); builder.Append('(');
builder.Append("((CleanName like @SearchTermStartsWith or (OriginalTitle not null and OriginalTitle like @SearchTermStartsWith)) * 10)"); builder.Append("((CleanName like @SearchTermStartsWith or (OriginalTitle not null and OriginalTitle like @SearchTermStartsWith)) * 10)");
@ -5238,7 +5239,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
{ {
if (i > 0) if (i > 0)
{ {
insertText.Append(","); insertText.Append(',');
} }
insertText.AppendFormat("(@ItemId, @AncestorId{0}, @AncestorIdText{0})", i.ToString(CultureInfo.InvariantCulture)); insertText.AppendFormat("(@ItemId, @AncestorId{0}, @AncestorIdText{0})", i.ToString(CultureInfo.InvariantCulture));
@ -6331,7 +6332,10 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
foreach (var column in _mediaAttachmentSaveColumns.Skip(1)) foreach (var column in _mediaAttachmentSaveColumns.Skip(1))
{ {
insertText.Append("@" + column + index + ","); insertText.Append('@')
.Append(column)
.Append(index)
.Append(',');
} }
insertText.Length -= 1; insertText.Length -= 1;

View File

@ -488,7 +488,8 @@ namespace Emby.Server.Implementations.Services
sb.Append(value); sb.Append(value);
for (var j = pathIx + 1; j < requestComponents.Length; j++) for (var j = pathIx + 1; j < requestComponents.Length; j++)
{ {
sb.Append(PathSeperatorChar + requestComponents[j]); sb.Append(PathSeperatorChar)
.Append(requestComponents[j]);
} }
value = sb.ToString(); value = sb.ToString();
@ -505,7 +506,8 @@ namespace Emby.Server.Implementations.Services
pathIx++; pathIx++;
while (!string.Equals(requestComponents[pathIx], stopLiteral, StringComparison.OrdinalIgnoreCase)) while (!string.Equals(requestComponents[pathIx], stopLiteral, StringComparison.OrdinalIgnoreCase))
{ {
sb.Append(PathSeperatorChar + requestComponents[pathIx++]); sb.Append(PathSeperatorChar)
.Append(requestComponents[pathIx++]);
} }
value = sb.ToString(); value = sb.ToString();

View File

@ -372,7 +372,7 @@ namespace MediaBrowser.Controller.MediaEncoding
public int GetVideoProfileScore(string profile) public int GetVideoProfileScore(string profile)
{ {
// strip spaces because they may be stripped out on the query string // strip spaces because they may be stripped out on the query string
profile = profile.Replace(" ", ""); profile = profile.Replace(" ", string.Empty, StringComparison.Ordinal);
return Array.FindIndex(_videoProfiles, x => string.Equals(x, profile, StringComparison.OrdinalIgnoreCase)); return Array.FindIndex(_videoProfiles, x => string.Equals(x, profile, StringComparison.OrdinalIgnoreCase));
} }
@ -468,13 +468,13 @@ namespace MediaBrowser.Controller.MediaEncoding
arg.Append("-hwaccel_output_format vaapi ") arg.Append("-hwaccel_output_format vaapi ")
.Append("-vaapi_device ") .Append("-vaapi_device ")
.Append(encodingOptions.VaapiDevice) .Append(encodingOptions.VaapiDevice)
.Append(" "); .Append(' ');
} }
else if (!isVaapiDecoder && isVaapiEncoder) else if (!isVaapiDecoder && isVaapiEncoder)
{ {
arg.Append("-vaapi_device ") arg.Append("-vaapi_device ")
.Append(encodingOptions.VaapiDevice) .Append(encodingOptions.VaapiDevice)
.Append(" "); .Append(' ');
} }
} }