Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public override string ConvertToString(object value, IValueSerializerContext con
// included in the output formulation -- UTC gets written out with a "Z",
// and Local gets written out with e.g. "-08:00" for Pacific Standard Time.

formatString.Append("K");
formatString.Append('K');

// We've finally got our format string built, we can create the string.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,7 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
if (value is NameFixupToken && parentProperty != XamlLanguage.Items)
{
NameFixupToken token = value as NameFixupToken;
string names = String.Join(",", token.NeededNames.ToArray());
string names = String.Join(',', token.NeededNames.ToArray());
Copy link

@sixlettervariables sixlettervariables Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, are these ToArray calls needed? It seems like NeededNames implements IEnumerable<String>. (Not that it probably matters on this exception oath)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would definetly be worth benchmarking but List may have optimization that makes it quick to return a copy of the internal array so I don't know if it is faster than enumerating with IEnumerable. My guess would be that ToArray is faster but uses more memory (It may vary with the number of item).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List creates a new array and copies elements over, while enumeration uses in-place value-type enumerator. It's a one method call vs. method call every item during enumerating, but also don't forget that the string.Join implementation differs - the array uses unsafe, pre-allocated char buffer while the enumerable uses StringBuilder to avoid double enumeration, and another difference is that changing the collection while being enumerated is illegal and throws.

That said, it probably doesn't matter here as it's an exception path and the number of items in the list would typically be quite small.

string msg = SR.Get(SRID.ForwardRefDirectives, names);
throw ctx.WithLineInfo(new XamlObjectWriterException(msg));
}
Expand Down Expand Up @@ -2033,7 +2033,7 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
// Only the key directive may be assigned a reference.
if (parentProperty != XamlLanguage.Key)
{
string names = String.Join(",", token.NeededNames.ToArray());
string names = String.Join(',', token.NeededNames.ToArray());
string msg = SR.Get(SRID.ForwardRefDirectives, names);
throw ctx.WithLineInfo(new XamlObjectWriterException(msg));
}
Expand Down Expand Up @@ -2086,7 +2086,7 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
if (parentProperty != XamlLanguage.Key)
{
NameFixupToken token = (NameFixupToken)value;
string names = String.Join(",", token.NeededNames.ToArray());
string names = String.Join(',', token.NeededNames.ToArray());
string msg = SR.Get(SRID.ForwardRefDirectives, names);
throw ctx.WithLineInfo(new XamlObjectWriterException(msg));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public static int IndexOf(string src, string chars)
return src.IndexOf(chars, StringComparison.Ordinal);
}

/// <summary>
/// Standard String Index search operation.
/// </summary>
public static int IndexOf(string src, char ch)
{
return src.IndexOf(ch, StringComparison.Ordinal);
}

public static bool EndsWith(string src, string target)
{
return src.EndsWith(target, StringComparison.Ordinal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private static string RemoveEscapes(string value)
value = value.Substring(2);
}

if (!value.Contains("\\"))
if (!value.Contains(Backslash))
{
return value;
}
Expand Down Expand Up @@ -352,7 +352,7 @@ private string ReadString()
// handle escaping and quoting first.
if(escaped)
{
sb.Append('\\');
sb.Append(Backslash);
sb.Append(ch);
escaped = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public XamlName(string prefix, string name)

public static bool ContainsDot(string name)
{
return name.Contains(".");
return name.Contains(Dot);
}

public static bool IsValidXamlName(string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static bool TryParseUri(string uriInput, out string clrNs, out string ass
// xmlns:bar="clr-namespace:MyAppsNs"
// xmlns:spam="clr-namespace:MyAppsNs;assembly="

int colonIdx = KS.IndexOf(uriInput, ":");
int colonIdx = KS.IndexOf(uriInput, ':');
if (colonIdx == -1)
{
return false;
Expand All @@ -36,7 +36,7 @@ public static bool TryParseUri(string uriInput, out string clrNs, out string ass
}

int clrNsStartIdx = colonIdx + 1;
int semicolonIdx = KS.IndexOf(uriInput, ";");
int semicolonIdx = KS.IndexOf(uriInput, ';');
if (semicolonIdx == -1)
{
clrNs = uriInput.Substring(clrNsStartIdx);
Expand All @@ -50,7 +50,7 @@ public static bool TryParseUri(string uriInput, out string clrNs, out string ass
}

int assemblyKeywordStartIdx = semicolonIdx+1;
int equalIdx = KS.IndexOf(uriInput, "=");
int equalIdx = KS.IndexOf(uriInput, '=');
if (equalIdx == -1)
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ protected static string FormatStringInCorrectSyntax(string s)

if (s[i] == '\\' || s[i] == '"')
{
sb.Append("\\");
sb.Append('\\');
}
sb.Append(s[i]);
}

sb.Append("\"");
sb.Append('\"');
return sb.ToString();
}

Expand All @@ -274,7 +274,7 @@ protected void WritePrefix(XamlMarkupExtensionWriter writer, string prefix)
if (!string.IsNullOrEmpty(prefix))
{
writer.sb.Append(prefix);
writer.sb.Append(":");
writer.sb.Append(':');
}
}

Expand Down Expand Up @@ -308,7 +308,7 @@ public override void WriteStartObject(XamlMarkupExtensionWriter writer, XamlType

string prefix = writer.LookupPrefix(type);

writer.sb.Append("{");
writer.sb.Append('{');
WritePrefix(writer, prefix);
writer.sb.Append(XamlXmlWriter.GetTypeName(type));

Expand Down Expand Up @@ -342,7 +342,7 @@ public override void WriteEndObject(XamlMarkupExtensionWriter writer)
throw new InvalidOperationException(SR.Get(SRID.XamlMarkupExtensionWriterInputInvalid));
}

writer.sb.Append("}");
writer.sb.Append('}');

if (writer.nodes.Count == 0)
{
Expand Down Expand Up @@ -419,7 +419,7 @@ protected void WriteNonPositionalParameterMember(XamlMarkupExtensionWriter write
writer.sb.Append(property.Name);
}

writer.sb.Append("=");
writer.sb.Append('=');

writer.currentState = InMember.State;
}
Expand Down Expand Up @@ -576,7 +576,7 @@ public override void WriteStartObject(XamlMarkupExtensionWriter writer, XamlType
}
string prefix = writer.LookupPrefix(type);

writer.sb.Append("{");
writer.sb.Append('{');
WritePrefix(writer, prefix);
writer.sb.Append(XamlXmlWriter.GetTypeName(type));

Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,19 +1361,19 @@ private void AppendTypeName(StringBuilder sb, bool forceNsInitialization)
}
if (!string.IsNullOrEmpty(ns))
{
sb.Append("{");
sb.Append('{');
sb.Append(PreferredXamlNamespace);
sb.Append("}");
sb.Append('}');
}
else if (UnderlyingTypeInternal.Value != null)
{
sb.Append(UnderlyingTypeInternal.Value.Namespace);
sb.Append(".");
sb.Append('.');
}
sb.Append(Name);
if (IsGeneric)
{
sb.Append("(");
sb.Append('(');
for (int i = 0; i < TypeArguments.Count; i++)
{
TypeArguments[i].AppendTypeName(sb, forceNsInitialization);
Expand All @@ -1382,7 +1382,7 @@ private void AppendTypeName(StringBuilder sb, bool forceNsInitialization)
sb.Append(", ");
}
}
sb.Append(")");
sb.Append(')');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ internal void ConvertToStringInternal(StringBuilder result, Func<string, string>
}
if (prefixGenerator == null)
{
result.Append("{");
result.Append('{');
result.Append(Namespace);
result.Append("}");
result.Append('}');
}
else
{
Expand All @@ -256,7 +256,7 @@ internal void ConvertToStringInternal(StringBuilder result, Func<string, string>
if (prefix.Length != 0)
{
result.Append(prefix);
result.Append(":");
result.Append(':');
}
}
if (HasTypeArgs)
Expand All @@ -266,9 +266,9 @@ internal void ConvertToStringInternal(StringBuilder result, Func<string, string>
string name = GenericTypeNameScanner.StripSubscript(Name, out subscript);
result.Append(name);

result.Append("(");
result.Append('(');
ConvertListToStringInternal(result, TypeArguments, prefixGenerator);
result.Append(")");
result.Append(')');

result.Append(subscript);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ void ConvertXamlTypeToStringHelper(XamlType type, StringBuilder builder)
if (type.TypeArguments != null)
{
bool added = false;
builder.Append("(");
builder.Append('(');
foreach (XamlType arg in type.TypeArguments)
{
if (added)
Expand All @@ -665,7 +665,7 @@ void ConvertXamlTypeToStringHelper(XamlType type, StringBuilder builder)
ConvertXamlTypeToStringHelper(arg, builder);
added = true;
}
builder.Append(")");
builder.Append(')');
}

// re-attach the subscript
Expand Down