5
5
// Jb Evain (jbevain@gmail.com)
7
// Copyright (c) 2008 - 2010 Jb Evain
9
9
// Permission is hereby granted, free of charge, to any person obtaining
10
10
// a copy of this software and associated documentation files (the
26
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
33
namespace Mono.Cecil.Metadata {
32
using System.Collections;
35
public class BlobHeap : MetadataHeap {
37
internal BlobHeap (MetadataStream stream) : base (stream, MetadataStream.Blob)
35
sealed class BlobHeap : Heap {
37
public BlobHeap (Section section, uint start, uint size)
38
: base (section, start, size)
41
42
public byte [] Read (uint index)
43
return ReadBytesFromStream (index);
46
public BinaryReader GetReader (uint index)
48
return new BinaryReader (new MemoryStream (Read (index)));
51
public override void Accept (IMetadataVisitor visitor)
53
visitor.VisitBlobHeap (this);
57
class ByteArrayEqualityComparer : IHashCodeProvider, IComparer {
59
public static readonly ByteArrayEqualityComparer Instance = new ByteArrayEqualityComparer ();
61
public int GetHashCode (object obj)
63
byte [] array = (byte []) obj;
66
for (int i = 0; i < array.Length; i++)
67
hash = (hash * 37) ^ array [i];
72
public int Compare (object a, object b)
74
byte [] x = (byte []) a;
75
byte [] y = (byte []) b;
77
if (x == null || y == null)
78
return x == y ? 0 : 1;
80
if (x.Length != y.Length)
83
for (int i = 0; i < x.Length; i++)
44
if (index == 0 || index > Size - 1)
45
return Empty<byte>.Array;
47
var data = Section.Data;
49
int position = (int) (index + Offset);
50
int length = (int) data.ReadCompressedUInt32 (ref position);
52
var buffer = new byte [length];
54
Buffer.BlockCopy (data, position, buffer, 0, length);