~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/Mono.Cecil/Mono.Cecil/Mono.Cecil.Metadata/BlobHeap.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
// Author:
5
5
//   Jb Evain (jbevain@gmail.com)
6
6
//
7
 
// (C) 2005 Jb Evain
 
7
// Copyright (c) 2008 - 2010 Jb Evain
8
8
//
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.
27
27
//
28
28
 
 
29
using System;
 
30
 
 
31
using Mono.Cecil.PE;
 
32
 
29
33
namespace Mono.Cecil.Metadata {
30
34
 
31
 
        using System;
32
 
        using System.Collections;
33
 
        using System.IO;
34
 
 
35
 
        public class BlobHeap : MetadataHeap {
36
 
 
37
 
                internal BlobHeap (MetadataStream stream) : base (stream, MetadataStream.Blob)
 
35
        sealed class BlobHeap : Heap {
 
36
 
 
37
                public BlobHeap (Section section, uint start, uint size)
 
38
                        : base (section, start, size)
38
39
                {
39
40
                }
40
41
 
41
42
                public byte [] Read (uint index)
42
43
                {
43
 
                        return ReadBytesFromStream (index);
44
 
                }
45
 
 
46
 
                public BinaryReader GetReader (uint index)
47
 
                {
48
 
                        return new BinaryReader (new MemoryStream (Read (index)));
49
 
                }
50
 
 
51
 
                public override void Accept (IMetadataVisitor visitor)
52
 
                {
53
 
                        visitor.VisitBlobHeap (this);
54
 
                }
55
 
        }
56
 
 
57
 
        class ByteArrayEqualityComparer : IHashCodeProvider, IComparer {
58
 
 
59
 
                public static readonly ByteArrayEqualityComparer Instance = new ByteArrayEqualityComparer ();
60
 
 
61
 
                public int GetHashCode (object obj)
62
 
                {
63
 
                        byte [] array = (byte []) obj;
64
 
 
65
 
                        int hash = 0;
66
 
                        for (int i = 0; i < array.Length; i++)
67
 
                                hash = (hash * 37) ^ array [i];
68
 
 
69
 
                        return hash;
70
 
                }
71
 
 
72
 
                public int Compare (object a, object b)
73
 
                {
74
 
                        byte [] x = (byte []) a;
75
 
                        byte [] y = (byte []) b;
76
 
 
77
 
                        if (x == null || y == null)
78
 
                                return x == y ? 0 : 1;
79
 
 
80
 
                        if (x.Length != y.Length)
81
 
                                return 1;
82
 
 
83
 
                        for (int i = 0; i < x.Length; i++)
84
 
                                if (x [i] != y [i])
85
 
                                        return 1;
86
 
 
87
 
                        return 0;
 
44
                        if (index == 0 || index > Size - 1)
 
45
                                return Empty<byte>.Array;
 
46
 
 
47
                        var data = Section.Data;
 
48
 
 
49
                        int position = (int) (index + Offset);
 
50
                        int length = (int) data.ReadCompressedUInt32 (ref position);
 
51
 
 
52
                        var buffer = new byte [length];
 
53
 
 
54
                        Buffer.BlockCopy (data, position, buffer, 0, length);
 
55
 
 
56
                        return buffer;
88
57
                }
89
58
        }
90
59
}