Skip to content

Commit

Permalink
Clean up unused. Add CLSCompliant to asm.
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusfriedman committed Oct 23, 2024
1 parent 23049d7 commit 27ef62e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 59 deletions.
13 changes: 0 additions & 13 deletions Common/Classes/Binary/Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2859,19 +2859,6 @@ public static int Log2i(uint v)
}

#endregion

#region Rounding

[CLSCompliant(false)]
public static uint RoundUpToNextMultiple(uint number, uint product)
=> (number + product) & ~product;

[CLSCompliant(false)]
public static uint RoundDownToNextMultiple(uint number, uint product)
=> number & ~product;

#endregion

}

//MemSet, Copy
Expand Down
106 changes: 60 additions & 46 deletions Common/Classes/MemorySegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,62 +463,64 @@ public bool Equals(MemorySegment other)
//}
#endif

/////!
//Should propably be the base class of MemorySegment because it's a lower order concept
/// <summary>
/// Extends MemorySegment with the ability to store certain bit offsets
/// </summary>
public class BitSegment : MemorySegment
{
private ulong m_BitOffset, m_BitCount;

public int BitCount
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get { return (int)m_BitCount; }
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
protected set { m_BitCount = (ulong)value; }
}
#region BitSegment

///////!
////Should propably be the base class of MemorySegment because it's a lower order concept
///// <summary>
///// Extends MemorySegment with the ability to store certain bit offsets
///// </summary>
//public class BitSegment : MemorySegment
//{
// private ulong m_BitOffset, m_BitCount;

public long LongBitCount
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get { return (long)m_BitCount; }
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
protected set { m_BitCount = (ulong)value; }
}
// public int BitCount
// {
// [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
// get { return (int)m_BitCount; }
// [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
// protected set { m_BitCount = (ulong)value; }
// }

public int BitOffset
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get { return (int)m_BitOffset; }
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
protected set { m_BitOffset = (ulong)value; }
}
// public long LongBitCount
// {
// [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
// get { return (long)m_BitCount; }
// [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
// protected set { m_BitCount = (ulong)value; }
// }

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public BitSegment(int bitSize, bool shouldDispose = true) : base(Common.Binary.BitsToBytes(ref bitSize), shouldDispose) { m_BitCount = (ulong)bitSize; }
// public int BitOffset
// {
// [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
// get { return (int)m_BitOffset; }
// [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
// protected set { m_BitOffset = (ulong)value; }
// }

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public BitSegment(byte[] reference, int bitOffset, int bitCount, bool shouldDispose = true)
: base(reference, Common.Binary.BitsToBytes(ref bitOffset), Common.Binary.BitsToBytes(ref bitCount), shouldDispose)
{
m_BitOffset = (ulong)bitOffset;
// [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
// public BitSegment(int bitSize, bool shouldDispose = true) : base(Common.Binary.BitsToBytes(ref bitSize), shouldDispose) { m_BitCount = (ulong)bitSize; }

m_BitCount = (ulong)bitCount;
}
// [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
// public BitSegment(byte[] reference, int bitOffset, int bitCount, bool shouldDispose = true)
// : base(reference, Common.Binary.BitsToBytes(ref bitOffset), Common.Binary.BitsToBytes(ref bitCount), shouldDispose)
// {
// m_BitOffset = (ulong)bitOffset;

//reference may be null
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public BitSegment(byte[] reference, int bitOffset, bool shouldDispose = true) : this(reference, bitOffset, Common.Binary.BytesToBits(reference.Length) - bitOffset, shouldDispose) { }
// m_BitCount = (ulong)bitCount;
// }

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public BitSegment(byte[] reference) : this(reference, 0, Common.Binary.BytesToBits(reference.Length)) { }
// //reference may be null
// [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
// public BitSegment(byte[] reference, int bitOffset, bool shouldDispose = true) : this(reference, bitOffset, Common.Binary.BytesToBits(reference.Length) - bitOffset, shouldDispose) { }

// [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
// public BitSegment(byte[] reference) : this(reference, 0, Common.Binary.BytesToBits(reference.Length)) { }

//Would have to implement a Copy virtual method to ensure that bitOffsets were not accidentally copied using Array.Copy
// //Would have to implement a Copy virtual method to ensure that bitOffsets were not accidentally copied using Array.Copy
//}

}
#endregion

/// <summary>
/// Provides useful extension methods for the <see cref="MemorySegment"/> class
Expand Down Expand Up @@ -593,6 +595,18 @@ public static void CopyTo(this MemorySegment segment, byte[] dest, int destinati
Array.Copy(segment.Array, segment.Offset, dest, destinationIndex, length);
}

/// <summary>
/// Copies the bytes from the segment to the stream
/// </summary>
/// <param name="segment"></param>
/// <param name="stream"></param>
public static void CopyTo(this MemorySegment segment, System.IO.Stream stream)
{
if (Common.IDisposedExtensions.IsNullOrDisposed(segment)) return;

stream.Write(segment.Array, segment.Offset, segment.Count);
}

//make Left / Right or expect the callers to use -length when they need to...
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static MemorySegment Subset(this MemorySegment segment, int offset, int length, bool shouldDispose = true)
Expand Down
2 changes: 2 additions & 0 deletions Ntp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]

[assembly: System.CLSCompliant(true)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b9788cdc-7365-4117-9711-2cfa2057D00B")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Media.UnitTests")]

0 comments on commit 27ef62e

Please sign in to comment.