This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
8,559 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/System.Reflection.Metadata/src/System/Reflection/Blob.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
#if SRM | ||
namespace System.Reflection | ||
#else | ||
namespace Roslyn.Reflection | ||
#endif | ||
{ | ||
#if SRM | ||
public | ||
#endif | ||
struct Blob | ||
{ | ||
internal readonly byte[] Buffer; | ||
internal readonly int Start; | ||
public int Length { get; } | ||
|
||
internal Blob(byte[] buffer, int start, int length) | ||
{ | ||
Buffer = buffer; | ||
Start = start; | ||
Length = length; | ||
} | ||
|
||
public bool IsDefault => Buffer == null; | ||
|
||
public ArraySegment<byte> GetBytes() => new ArraySegment<byte>(Buffer, Start, Length); | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
src/System.Reflection.Metadata/src/System/Reflection/BlobBuilder.Enumerators.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Diagnostics; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System; | ||
|
||
#if SRM | ||
namespace System.Reflection | ||
#else | ||
namespace Roslyn.Reflection | ||
#endif | ||
{ | ||
partial class BlobBuilder | ||
{ | ||
// internal for testing | ||
internal struct Chunks : IEnumerable<BlobBuilder>, IEnumerator<BlobBuilder>, IEnumerator | ||
{ | ||
private readonly BlobBuilder _head; | ||
private BlobBuilder _next; | ||
private BlobBuilder _currentOpt; | ||
|
||
internal Chunks(BlobBuilder builder) | ||
{ | ||
Debug.Assert(builder.IsHead); | ||
|
||
_head = builder; | ||
_next = builder.FirstChunk; | ||
_currentOpt = null; | ||
} | ||
|
||
object IEnumerator.Current => Current; | ||
public BlobBuilder Current => _currentOpt; | ||
|
||
public bool MoveNext() | ||
{ | ||
if (_currentOpt == _head) | ||
{ | ||
return false; | ||
} | ||
|
||
if (_currentOpt == _head._nextOrPrevious) | ||
{ | ||
_currentOpt = _head; | ||
return true; | ||
} | ||
|
||
_currentOpt = _next; | ||
_next = _next._nextOrPrevious; | ||
return true; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
_currentOpt = null; | ||
_next = _head.FirstChunk; | ||
} | ||
|
||
void IDisposable.Dispose() { } | ||
|
||
// IEnumerable: | ||
public Chunks GetEnumerator() => this; | ||
IEnumerator<BlobBuilder> IEnumerable<BlobBuilder>.GetEnumerator() => GetEnumerator(); | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
|
||
public struct Blobs : IEnumerable<Blob>, IEnumerator<Blob>, IEnumerator | ||
{ | ||
private Chunks _chunks; | ||
|
||
internal Blobs(BlobBuilder builder) | ||
{ | ||
_chunks = new Chunks(builder); | ||
} | ||
|
||
object IEnumerator.Current => Current; | ||
|
||
public Blob Current | ||
{ | ||
get | ||
{ | ||
var current = _chunks.Current; | ||
if (current != null) | ||
{ | ||
return new Blob(current._buffer, 0, current.Length); | ||
} | ||
else | ||
{ | ||
return default(Blob); | ||
} | ||
} | ||
} | ||
|
||
public bool MoveNext() => _chunks.MoveNext(); | ||
public void Reset() => _chunks.Reset(); | ||
|
||
void IDisposable.Dispose() { } | ||
|
||
// IEnumerable: | ||
public Blobs GetEnumerator() => this; | ||
IEnumerator<Blob> IEnumerable<Blob>.GetEnumerator() => GetEnumerator(); | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
} | ||
} |
Oops, something went wrong.