Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Closed
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 @@ -345,9 +345,11 @@ void ICollection.CopyTo(Array array, int arrayIndex)
Requires.Range(arrayIndex >= 0, "arrayIndex");
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");

int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
foreach (var item in this)
{
array.SetValue(new DictionaryEntry(item.Key, item.Value), arrayIndex++);
indices[0] = arrayIndex++;
array.SetValue(new DictionaryEntry(item.Key, item.Value), indices);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,11 @@ void ICollection.CopyTo(Array array, int arrayIndex)
Requires.Range(arrayIndex >= 0, "arrayIndex");
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");

int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
foreach (var item in this)
{
array.SetValue(new DictionaryEntry(item.Key, item.Value), arrayIndex++);
indices[0] = arrayIndex++;
array.SetValue(new DictionaryEntry(item.Key, item.Value), indices);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,11 @@ void ICollection.CopyTo(Array array, int arrayIndex)
Requires.Range(arrayIndex >= 0, "arrayIndex");
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");

int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
foreach (T item in this)
{
array.SetValue(item, arrayIndex++);
indices[0] = arrayIndex++;
array.SetValue(item, indices);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2590,9 +2590,11 @@ internal void CopyTo(Array array, int arrayIndex)
Requires.Range(arrayIndex >= 0, "arrayIndex");
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");

int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
foreach (var element in this)
{
array.SetValue(element, arrayIndex++);
indices[0] = arrayIndex++;
array.SetValue(element, indices);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,9 +1381,11 @@ internal void CopyTo(Array array, int arrayIndex, int dictionarySize)
Requires.Range(arrayIndex >= 0, "arrayIndex");
Requires.Range(array.Length >= arrayIndex + dictionarySize, "arrayIndex");

int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
foreach (var item in this)
{
array.SetValue(new DictionaryEntry(item.Key, item.Value), arrayIndex++);
indices[0] = arrayIndex++;
array.SetValue(new DictionaryEntry(item.Key, item.Value), indices);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1689,9 +1689,11 @@ internal void CopyTo(Array array, int arrayIndex)
Requires.Range(arrayIndex >= 0, "arrayIndex");
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");

int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
foreach (var item in this)
{
array.SetValue(item, arrayIndex++);
indices[0] = arrayIndex++;
array.SetValue(item, indices);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ void ICollection.CopyTo(Array array, int arrayIndex)
Requires.Range(arrayIndex >= 0, "arrayIndex");
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");

int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
foreach (T item in this)
{
array.SetValue(item, arrayIndex++);
indices[0] = arrayIndex++;
array.SetValue(item, indices);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace System.Reflection.Metadata
[DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
public unsafe struct BlobReader
{
/// <summary>An array containing the '\0' character.</summary>
private static readonly char[] _nullCharArray = new char[1] { '\0' };

internal const int InvalidCompressedInteger = Int32.MaxValue;

private readonly MemoryBlock block;
Expand Down Expand Up @@ -482,7 +485,7 @@ public string ReadSerializedString()
{
// Removal of trailing '\0' is a departure from the spec, but required
// for compatibility with legacy compilers.
return ReadUTF8(length).TrimEnd('\0');
return ReadUTF8(length).TrimEnd(_nullCharArray);
}

if (ReadByte() != 0xFF)
Expand Down
2 changes: 1 addition & 1 deletion src/System.Xml.Common/System/Xml/XmlRawWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public override void WriteCData(string text)
// Forward call to WriteString(string).
public override void WriteCharEntity(char ch)
{
WriteString(new string(new char[] { ch }));
WriteString(new string(ch, 1));
}

// Forward call to WriteString(string).
Expand Down
4 changes: 3 additions & 1 deletion src/System.Xml.XDocument/System/Xml/Linq/XLinq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8779,6 +8779,8 @@ void AddString(string s)

internal class XNodeReader : XmlReader, IXmlLineInfo
{
private static readonly char[] WhitespaceChars = new char[] { ' ', '\t', '\n', '\r' };

// The reader position is encoded by the tuple (source, parent).
// Lazy text uses (instance, parent element). Attribute value
// uses (instance, parent attribute). End element uses (instance,
Expand Down Expand Up @@ -9200,7 +9202,7 @@ public override XmlSpace XmlSpace
XAttribute a = e.Attribute(name);
if (a != null)
{
switch (a.Value.Trim(new char[] { ' ', '\t', '\n', '\r' }))
switch (a.Value.Trim(WhitespaceChars))
{
case "preserve":
return XmlSpace.Preserve;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ public override void WriteEntityRef(string name)
/// </summary>
public override void WriteCharEntity(char ch)
{
char[] chars = { ch };
WriteString(new string(chars), TextBlockType.Text);
WriteString(new string(ch, 1), TextBlockType.Text);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,12 @@ public void RemoveAll()

void ICollection.CopyTo(Array array, int index)
{
int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
for (int i = 0, max = Count; i < max; i++, index++)
array.SetValue(nodes[i], index);
{
indices[0] = index;
array.SetValue(nodes[i], indices);
}
}

bool ICollection.IsSynchronized
Expand Down