Skip to content

Commit

Permalink
Address some PR comments.
Browse files Browse the repository at this point in the history
Remove EnumExtensions in favor of casting to int and using CompareTo.
Move array allocation out of loop in CopiedFieldRvaNode.
  • Loading branch information
Anubhav Srivastava committed Dec 11, 2019
1 parent 40f6522 commit 964ec9d
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
private unsafe byte[] GetRvaData(int targetPointerSize)
{
int size = 0;
byte[] result = Array.Empty<byte>();

MetadataReader metadataReader = _module.MetadataReader;
BlobReader metadataBlob = new BlobReader(_module.PEReader.GetMetadata().Pointer, _module.PEReader.GetMetadata().Length);
Expand All @@ -78,7 +77,6 @@ private unsafe byte[] GetRvaData(int targetPointerSize)
// We need to handle overlapping fields by reusing blobs based on the rva, and just update
// the size and contents
size = currentSize;
result = new byte[AlignmentHelper.AlignUp(size, targetPointerSize)];
}
}

Expand All @@ -88,6 +86,7 @@ private unsafe byte[] GetRvaData(int targetPointerSize)
if (block.Length < size)
throw new BadImageFormatException();

byte[] result = new byte[AlignmentHelper.AlignUp(size, targetPointerSize)];
block.GetContent(0, size).CopyTo(result);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override void AppendMangledName(NameMangler nameMangler, Utf8StringBuilde
public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
{
FieldFixupSignature otherNode = (FieldFixupSignature)other;
int result = _fixupKind.CompareEnum(otherNode._fixupKind);
int result = ((int)_fixupKind).CompareTo((int)otherNode._fixupKind);
if (result != 0)
return result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ public override void AppendMangledName(NameMangler nameMangler, Utf8StringBuilde
public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
{
GenericLookupSignature otherNode = (GenericLookupSignature)other;
int result = _runtimeLookupKind.CompareEnum(otherNode._runtimeLookupKind);
int result = ((int)_runtimeLookupKind).CompareTo((int)otherNode._runtimeLookupKind);
if (result != 0)
return result;

result = _fixupKind.CompareEnum(otherNode._fixupKind);
result = ((int)_fixupKind).CompareTo((int)otherNode._fixupKind);
if (result != 0)
return result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

using Internal.Text;
using Internal.ReadyToRunConstants;

Expand All @@ -15,7 +13,7 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun
/// </summary>
public partial class ImportThunk : AssemblyStubNode, ISymbolDefinitionNode
{
public enum Kind
enum Kind
{
Eager,
Lazy,
Expand Down Expand Up @@ -76,7 +74,7 @@ protected override string GetName(NodeFactory factory)
public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
{
ImportThunk otherNode = (ImportThunk)other;
int result = _thunkKind.CompareEnum(otherNode._thunkKind);
int result = ((int)_thunkKind).CompareTo((int)otherNode._thunkKind);
if (result != 0)
return result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public override void AppendMangledName(NameMangler nameMangler, Utf8StringBuilde
public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
{
MethodFixupSignature otherNode = (MethodFixupSignature)other;
int result = _fixupKind.CompareEnum(otherNode._fixupKind);
int result = ((int)_fixupKind).CompareTo((int)otherNode._fixupKind);
if (result != 0)
return result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public bool Equals(ModuleToken moduleToken)

public int CompareTo(ModuleToken other)
{
int result = Token.CompareEnum(other.Token);
int result = ((int)Token).CompareTo((int)Token);
if (result != 0)
return result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void AppendMangledName(NameMangler nameMangler, Utf8StringBuilde
public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
{
TypeFixupSignature otherNode = (TypeFixupSignature)other;
int result = _fixupKind.CompareEnum(otherNode._fixupKind);
int result = ((int)_fixupKind).CompareTo((int)otherNode._fixupKind);
if (result != 0)
return result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<Compile Include="..\..\Common\Internal\NativeFormat\NativeFormat.cs" Link="Common\NativeFormat.cs" />
<Compile Include="..\..\Common\Internal\NativeFormat\NativeFormatWriter.cs" Link="Common\NativeFormatWriter.cs" />
<Compile Include="..\..\Common\Internal\NativeFormat\NativeFormatWriter.Primitives.cs" Link="Common\NativeFormatWriter.Primitives.cs" />
<Compile Include="..\..\Common\System\EnumExtensions.cs" Link="Common\EnumExtensions.cs" />
<Compile Include="..\..\Common\System\FormattingHelpers.cs" Link="Common\FormattingHelpers.cs" />
<Compile Include="..\..\Common\TypeSystem\IL\ILProvider.cs" Link="IL\ILProvider.cs" />
<Compile Include="..\..\Common\TypeSystem\IL\Stubs\ComparerIntrinsics.cs" Link="IL\Stubs\ComparerIntrinsics.cs" />
Expand Down

0 comments on commit 964ec9d

Please sign in to comment.