Skip to content

Commit

Permalink
Use Length instead of Count()
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Jun 6, 2024
1 parent 6ced45e commit 8b83d08
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/Aardvark.Base/Extensions/ArrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public static void CopyRange<T>(this T[] array, long start, long count, long tar
}

/// <summary>
/// Create a copy with the elements reversed.
/// Create a copy with the elements reversed.
/// </summary>
public static T[] CopyReversed<T>(this T[] array)
{
Expand Down Expand Up @@ -1577,7 +1577,7 @@ public static T[] ForwardMappedCopyFrom<T>(
int[][] forwardMaps)
{
var offset = 0;
for (int i = 0; i < sourceArrays.Count(); i++)
for (int i = 0; i < sourceArrays.Length; i++)
{
sourceArrays[i].ForwardMappedCopyTo(
targetArray, forwardMaps[i], offset);
Expand Down Expand Up @@ -1655,7 +1655,7 @@ public static int[] BackMappedCopyIndexArrayTo(
int[] backwardMap,
int targetOffest)
{
int count = backwardMap.Count();
int count = backwardMap.Length;
int targetIndexOffset = targetArray.Max() + 1;

// creating targetArray, still indexing sourceArray
Expand Down Expand Up @@ -1705,7 +1705,7 @@ public static int[] BackMappedCopyIndexArrayTo(
out int[] targetArray,
int[] backwardMap)
{
targetArray = new int[backwardMap.Count()].Set(-1);
targetArray = new int[backwardMap.Length].Set(-1);
return sourceArray.BackMappedCopyIndexArrayTo(
targetArray, backwardMap, 0);
}
Expand All @@ -1721,7 +1721,7 @@ public static int[][] ForwardMappedCopyFromIndexArrays(
int[][] sourceArrays,
int[][] forwardMaps)
{
var count = sourceArrays.Count();
var count = sourceArrays.Length;
var indexMaps = new int[count][];
var offset = 0;
for (int i = 0; i < count; i++)
Expand All @@ -1745,15 +1745,15 @@ public static int[][] BackMappedCopyFromIndexArrays(
int[][] sourceArrays,
int[][] backwardMaps)
{
var count = sourceArrays.Count();
var count = sourceArrays.Length;
var indexMaps = new int[count][];
var offset = 0;
for (int i = 0; i < count; i++)
{
indexMaps[i] = sourceArrays[i]
.BackMappedCopyIndexArrayTo(
targetArray, backwardMaps[i], offset);
offset += backwardMaps[i].Count();
offset += backwardMaps[i].Length;
}
return indexMaps;
}
Expand Down Expand Up @@ -1934,7 +1934,7 @@ public static double Integrate(this double[] array, double sum = 0.0)
}

/// <summary>
/// Creates an array that contains the integrated sum up to each element of input array.
/// Creates an array that contains the integrated sum up to each element of input array.
/// The length of the integrated array is +1 of the input array and contains the total
/// sum in the last element.
/// Using double precision during integration.
Expand All @@ -1952,7 +1952,7 @@ public static float[] Integrated(this float[] array, double sum = 0)
}

/// <summary>
/// Creates an array that contains the integrated sum up to each element of input array.
/// Creates an array that contains the integrated sum up to each element of input array.
/// The length of the integrated array is +1 of the input array and contains the total
/// sum in the last element.
/// Using single precision during integration.
Expand All @@ -1970,7 +1970,7 @@ public static float[] Integrated(this float[] array, float sum = 0)
}

/// <summary>
/// Creates an array that contains the integrated sum up to each element of input array.
/// Creates an array that contains the integrated sum up to each element of input array.
/// The length of the integrated array is +1 of the input array and contains the total
/// sum in the last element.
/// </summary>
Expand All @@ -1987,7 +1987,7 @@ public static int[] Integrated(this int[] array, int sum = 0)
}

/// <summary>
/// Creates an array that contains the integrated sum up to each element of input array.
/// Creates an array that contains the integrated sum up to each element of input array.
/// The length of the integrated array is +1 of the input array and contains the total
/// sum in the last element.
/// </summary>
Expand All @@ -2004,7 +2004,7 @@ public static long[] Integrated(this long[] array, long sum = 0)
}

/// <summary>
/// Creates an array that contains the integrated sum up to each element of input array.
/// Creates an array that contains the integrated sum up to each element of input array.
/// The length of the integrated array is +1 of the input array and contains the total
/// sum in the last element.
/// </summary>
Expand Down Expand Up @@ -2343,21 +2343,21 @@ public static Span<byte> AsByteSpan(this Array data)
{
var elementSize = data.GetType().GetElementType().GetCLRSize();
var span = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetArrayDataReference(data), data.Length * elementSize);
return span;
return span;
}

public static Span<byte> AsByteSpan<T>(this T[] data) where T : struct
{
var span = new Span<T>(data);
return MemoryMarshal.AsBytes(span);
}

public static ReadOnlySpan<byte> AsByteSpan(this string data)
{
return MemoryMarshal.AsBytes(data.AsSpan());
}
#endif

internal static unsafe T UseAsStream<T>(this Array data, Func<UnmanagedMemoryStream, T> action)
{
var gc = GCHandle.Alloc(data, GCHandleType.Pinned);
Expand All @@ -2375,7 +2375,7 @@ internal static unsafe T UseAsStream<T>(this Array data, Func<UnmanagedMemoryStr
gc.Free();
}
}

internal static unsafe void UseAsStream(this Array data, Action<UnmanagedMemoryStream> action)
{
var gc = GCHandle.Alloc(data, GCHandleType.Pinned);
Expand All @@ -2393,8 +2393,8 @@ internal static unsafe void UseAsStream(this Array data, Action<UnmanagedMemoryS
gc.Free();
}
}


#endregion

#region Hashes
Expand All @@ -2419,8 +2419,8 @@ public static byte[] ComputeMD5Hash(this byte[] data)
#endif
}



/// <summary>
/// Computes the MD5 hash of the data array.
/// </summary>
Expand All @@ -2432,7 +2432,7 @@ public static byte[] ComputeMD5Hash(this Array data)
Array.Resize(ref hash, 16);
return hash;
#else

using(var sha = SHA1.Create())
{
var hash = data.UseAsStream((stream) => sha.ComputeHash(stream));
Expand Down Expand Up @@ -2488,7 +2488,7 @@ public static byte[] ComputeSHA1Hash(this Array data)
return data.UseAsStream((stream) => sha.ComputeHash(stream));
}
#endif

}

/// <summary>
Expand Down Expand Up @@ -2620,7 +2620,7 @@ public static uint ComputeAdler32Checksum(this Array data)
data.UseAsStream((stream) => a.Update(stream));
#endif
}
return a.Checksum;
return a.Checksum;
}

/// <summary>
Expand All @@ -2629,7 +2629,7 @@ public static uint ComputeAdler32Checksum(this Array data)
public static uint ComputeAdler32Checksum(this string s)
{
var a = new Adler32();

#if NET6_0_OR_GREATER
a.Update(s.AsByteSpan());
#else
Expand Down

0 comments on commit 8b83d08

Please sign in to comment.