Skip to content

Commit

Permalink
Prefer StringBuilder.Append(char) over Append(string) (dotnet#32467)
Browse files Browse the repository at this point in the history
* Prefer StringBuilder.Append(char) over Append(string)

* Address PR feedback
  • Loading branch information
stephentoub authored Feb 18, 2020
1 parent e7cd7bc commit 0f736f8
Show file tree
Hide file tree
Showing 65 changed files with 240 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private static void AppendEscapedChar(StringBuilder b, char value)
{
b.Append("&Global.Microsoft.VisualBasic.ChrW(");
b.Append(((int)value).ToString(CultureInfo.InvariantCulture));
b.Append(")");
b.Append(')');
}

protected override void ProcessCompilerOutputLine(CompilerResults results, string line)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ internal static string GetTypeIdentityFromMethod(MethodInfo method, bool formatG

WriteTypeWithNamespace(methodNameStringBuilder, method.ReturnType, formatGenericName);

methodNameStringBuilder.Append("(");
methodNameStringBuilder.Append('(');

ParameterInfo[] parameters = method.GetParameters();

for (int i = 0; i < parameters.Length; i++)
{
if (i != 0)
{
methodNameStringBuilder.Append(",");
methodNameStringBuilder.Append(',');
}

WriteTypeWithNamespace(methodNameStringBuilder, parameters[i].ParameterType, formatGenericName);
}
methodNameStringBuilder.Append(")");
methodNameStringBuilder.Append(')');

return methodNameStringBuilder.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private string GetTypesDisplay()
if (builder.Length > 0)
{
builder.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator);
builder.Append(" ");
builder.Append(' ');
}

builder.Append(definition.GetPartType().GetDisplayName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,9 +1246,9 @@ internal void ReportInvalidLock(string attribToLockTrim, ConfigurationLockCollec
{
if (sb.Length != 0)
sb.Append(", ");
sb.Append("'");
sb.Append('\'');
sb.Append(validProp.Name);
sb.Append("'");
sb.Append('\'');
}
}
else
Expand All @@ -1257,9 +1257,9 @@ internal void ReportInvalidLock(string attribToLockTrim, ConfigurationLockCollec
{
if (sb.Length != 0)
sb.Append(", ");
sb.Append("'");
sb.Append('\'');
sb.Append(validProp.Name);
sb.Append("'");
sb.Append('\'');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,22 +834,22 @@ private string RetrieveFullOpenElementTag()

// Start with element tag name
StringBuilder element = new StringBuilder(64);
element.Append("<");
element.Append('<');
element.Append(Reader.Name);

// Add attributes
while (Reader.MoveToNextAttribute())
{
element.Append(" ");
element.Append(' ');
element.Append(Reader.Name);
element.Append("=");
element.Append('=');
element.Append('\"');
element.Append(Reader.Value);
element.Append('\"');
}

// Now close the element tag
element.Append(">");
element.Append('>');

return element.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key

if ((0 < builder.Length) && (';' != builder[builder.Length - 1]))
{
builder.Append(";");
builder.Append(';');
}

if (useOdbcRules)
Expand All @@ -143,7 +143,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
{
builder.Append(keyName.Replace("=", "=="));
}
builder.Append("=");
builder.Append('=');

if (null != keyValue)
{ // else <keyword>=;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key

if ((0 < builder.Length) && (';' != builder[builder.Length - 1]))
{
builder.Append(";");
builder.Append(';');
}

if (useOdbcRules)
Expand All @@ -204,7 +204,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
{
builder.Append(keyName.Replace("=", "=="));
}
builder.Append("=");
builder.Append('=');

if (null != keyValue)
{ // else <keyword>=;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ private string ValidateConnectionString(string connectionString)

StringBuilder builder = new StringBuilder();
builder.Append(KEY.Ole_DB_Services);
builder.Append("=");
builder.Append('=');
builder.Append(_oledbServices.ToString(CultureInfo.InvariantCulture));
builder.Append(";");
builder.Append(';');
builder.Append(connectionString);
connectionString = builder.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private DataTable GetDataSourceInformationTable(OleDbConnection connection, OleD
compositeSeparatorPattern.Append(patternEscaped.ToString());
if ((schemaSeparatorPattern != null) && (schemaSeparatorPattern != catalogSeparatorPattern))
{
compositeSeparatorPattern.Append("|");
compositeSeparatorPattern.Append('|');
patternEscaped.Length = 0;
ADP.EscapeSpecialCharacters(schemaSeparatorPattern, patternEscaped);
compositeSeparatorPattern.Append(patternEscaped.ToString());
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Data.OleDb/src/OleDb_Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ internal static string ELookup(OleDbHResult hr)
}
builder.Append("(0x");
builder.Append(((int)hr).ToString("X8", CultureInfo.InvariantCulture));
builder.Append(")");
builder.Append(')');
return builder.ToString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ public string Message
{
if (i != 0)
msgBuf.Append(", ");
msgBuf.Append("'");
msgBuf.Append('\'');
msgBuf.Append(strings[i]);
msgBuf.Append("'");
msgBuf.Append('\'');
}

msg = msgBuf.ToString();
Expand Down Expand Up @@ -418,9 +418,9 @@ private string GetMessageLibraryNames(string libRegKey)
{
result.Append(@"\\");
result.Append(owner.MachineName);
result.Append(@"\");
result.Append('\\');
result.Append(fileNames[i][0]);
result.Append("$");
result.Append('$');
result.Append(fileNames[i], 2, fileNames[i].Length - 2);
result.Append(';');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ private static StringBuilder BuildCommandLine(string executableFileName, string

if (!string.IsNullOrEmpty(arguments))
{
commandLine.Append(" ");
commandLine.Append(' ');
commandLine.Append(arguments);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ public virtual void Fail(string message, string detailMessage)
{
StringBuilder failMessage = new StringBuilder();
failMessage.Append(SR.TraceListenerFail);
failMessage.Append(" ");
failMessage.Append(' ');
failMessage.Append(message);
if (detailMessage != null)
{
failMessage.Append(" ");
failMessage.Append(' ');
failMessage.Append(detailMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected override string GetObjectClassPortion(Type principalType)
{
filter.Append("(objectClass=");
filter.Append(objectClass);
filter.Append(")");
filter.Append(')');
}

_cachedBindableObjectFilter = filter.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,22 +1049,22 @@ private ResultSet FindByDate(Type subtype, string[] ldapAttributes, MatchType ma

foreach (string ldapAttribute in ldapAttributes)
{
ldapFilter.Append("(");
ldapFilter.Append('(');

switch (matchType)
{
case MatchType.Equals:
ldapFilter.Append(ldapAttribute);
ldapFilter.Append("=");
ldapFilter.Append('=');
ldapFilter.Append(ldapValue);
break;

case MatchType.NotEquals:
ldapFilter.Append("!(");
ldapFilter.Append(ldapAttribute);
ldapFilter.Append("=");
ldapFilter.Append('=');
ldapFilter.Append(ldapValue);
ldapFilter.Append(")");
ldapFilter.Append(')');
break;

case MatchType.GreaterThanOrEquals:
Expand All @@ -1080,24 +1080,24 @@ private ResultSet FindByDate(Type subtype, string[] ldapAttributes, MatchType ma
break;

case MatchType.GreaterThan:
ldapFilter.Append("&");
ldapFilter.Append('&');

// Greater-than-or-equals (or less-than-or-equals))
ldapFilter.Append("(");
ldapFilter.Append('(');
ldapFilter.Append(ldapAttribute);
ldapFilter.Append(matchType == MatchType.GreaterThan ? ">=" : "<=");
ldapFilter.Append(ldapValue);
ldapFilter.Append(")");
ldapFilter.Append(')');

// And not-equal
ldapFilter.Append("(!(");
ldapFilter.Append(ldapAttribute);
ldapFilter.Append("=");
ldapFilter.Append('=');
ldapFilter.Append(ldapValue);
ldapFilter.Append("))");

// And exists (need to include because of tristate LDAP logic)
ldapFilter.Append("(");
ldapFilter.Append('(');
ldapFilter.Append(ldapAttribute);
ldapFilter.Append("=*)");
break;
Expand All @@ -1110,7 +1110,7 @@ private ResultSet FindByDate(Type subtype, string[] ldapAttributes, MatchType ma
break;
}

ldapFilter.Append(")");
ldapFilter.Append(')');
}

ldapFilter.Append("))");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,13 +628,13 @@ private Principal FindPrincipalByIdentRefHelper(
innerLdapFilter.Append(filterVal);
}

innerLdapFilter.Append(")");
innerLdapFilter.Append(')');

ldapFilter.Append(innerLdapFilter.ToString());
}

// Wrap off the filter
ldapFilter.Append(")");
ldapFilter.Append(')');

ds.Filter = ldapFilter.ToString();
GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "FindPrincipalByIdentRefHelper: using LDAP filter {0}", ds.Filter);
Expand Down Expand Up @@ -1244,7 +1244,7 @@ protected static void CommaStringToLdapConverter(Principal p, string propertyNam
// Preexisting values that have not been removed.
// This also includes inserted values.
sb.Append(value);
sb.Append(",");
sb.Append(',');
}

// We have an extra comma at the end (assuming we added any values to the string). Remove it.
Expand Down
Loading

0 comments on commit 0f736f8

Please sign in to comment.