Skip to content

Commit

Permalink
Remove DangerousGet methods (without unaligned), DangerousGetRef does…
Browse files Browse the repository at this point in the history
… that.
  • Loading branch information
buybackoff committed Jan 12, 2020
1 parent 8b592ea commit d3cacc2
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions dotnet/src/Spreads.Native/Vec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,14 @@ internal int RuntimeTypeId
public T this[int index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => Get(index);
get
{
if (unchecked((uint)index) >= unchecked((uint)_length))
{
VecThrowHelper.ThrowIndexOutOfRangeException();
}
return DangerousGetUnaligned(index);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
Expand All @@ -231,28 +238,6 @@ public T this[int index]
}
}

/// <summary>
/// Returns the element at the specified index.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Get(int index)
{
if (unchecked((uint)index) >= unchecked((uint)_length))
{
VecThrowHelper.ThrowIndexOutOfRangeException();
}
return DangerousGetUnaligned(index);
}

/// <summary>
/// Returns the element at the specified index without bound checks.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T DangerousGet(int index)
{
return DangerousGetRef(index);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T DangerousGetUnaligned(int index)
{
Expand Down Expand Up @@ -494,7 +479,7 @@ public Enumerator(Vec<T> vec)
public T Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _vec.DangerousGet(_position);
get => _vec.DangerousGetUnaligned(_position);
}

// ReSharper disable once HeapView.BoxingAllocation
Expand Down Expand Up @@ -806,7 +791,21 @@ public T Get<T>(int index)
ThrowWrongLengthOrType<T>(index);
}

return UnsafeEx.GetRef<T>(_pinnable, _byteOffset, index);
return DangerousGetUnaligned<T>(index);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set<T>(int index, T value)
{
if ((VecTypeHelper<T>.RuntimeTypeId != _runtimeTypeId)
||
(unchecked((uint)index) >= unchecked((uint)_length))
)
{
ThrowWrongLengthOrType<T>(index);
}

DangerousSetUnaligned<T>(index, value);
}

/// <summary>
Expand Down Expand Up @@ -840,15 +839,6 @@ private void ThrowWrongLengthOrType<T>(int index)
}
}

/// <summary>
/// Returns the element at the specified index without type or bounds check.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T DangerousGet<T>(int index)
{
return DangerousGetRef<T>(index);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T DangerousGetUnaligned<T>(int index)
{
Expand Down

0 comments on commit d3cacc2

Please sign in to comment.