Skip to content

Commit

Permalink
Merge pull request dotnet/corefx#151 from KrzysztofCwalina/dotnet2
Browse files Browse the repository at this point in the history
Removes some string-related allocations from XML libraries

Commit migrated from dotnet/corefx@92cfd41
  • Loading branch information
ellismg committed Nov 24, 2014
2 parents c4a1d6c + f07156b commit c97e5f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
19 changes: 13 additions & 6 deletions src/libraries/Common/src/System/Xml/XmlTextWriter.cs
Expand Up @@ -408,23 +408,27 @@ public override void WriteDocType(string name, string pubid, string sysid, strin
textWriter.Write(name);
if (pubid != null)
{
textWriter.Write(" PUBLIC " + quoteChar);
textWriter.Write(" PUBLIC ");
textWriter.Write(quoteChar);
textWriter.Write(pubid);
textWriter.Write(quoteChar + " " + quoteChar);
textWriter.Write(quoteChar);
textWriter.Write(' ');
textWriter.Write(quoteChar);
textWriter.Write(sysid);
textWriter.Write(quoteChar);
}
else if (sysid != null)
{
textWriter.Write(" SYSTEM " + quoteChar);
textWriter.Write(" SYSTEM ");
textWriter.Write(quoteChar);
textWriter.Write(sysid);
textWriter.Write(quoteChar);
}
if (subset != null)
{
textWriter.Write("[");
textWriter.Write('[');
textWriter.Write(subset);
textWriter.Write("]");
textWriter.Write(']');
}
textWriter.Write('>');
}
Expand Down Expand Up @@ -1122,7 +1126,10 @@ void StartDocument(int standalone)
this.currentState = State.Prolog;

StringBuilder bufBld = new StringBuilder(128);
bufBld.Append("version=" + quoteChar + "1.0" + quoteChar);
bufBld.Append("version=");
bufBld.Append(quoteChar);
bufBld.Append("1.0");
bufBld.Append(quoteChar);
if (this.encoding != null)
{
bufBld.Append(" encoding=");
Expand Down
Expand Up @@ -72,18 +72,20 @@ public override string InnerText
{
get
{
StringBuilder strb = new StringBuilder("version=\"" + Version + "\"");
StringBuilder strb = new StringBuilder("version=\"");
strb.Append(Version);
strb.Append('"');
if (Encoding.Length > 0)
{
strb.Append(" encoding=\"");
strb.Append(Encoding);
strb.Append("\"");
strb.Append('"');
}
if (Standalone.Length > 0)
{
strb.Append(" standalone=\"");
strb.Append(Standalone);
strb.Append("\"");
strb.Append('"');
}
return strb.ToString();
}
Expand Down

0 comments on commit c97e5f2

Please sign in to comment.