// ╔════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
// ║ Licensed under Unity Asset Store Terms of Service: ║
// ║ https://unity.com/legal/as-terms ║
// ║ Use permitted only in compliance with the License. ║
// ║ Distributed "AS IS", without warranty of any kind. ║
// ╚════════════════════════════════════════════════════════════════╝
#region
using System;
#endregion
namespace NWH.Common.Utility
{
///
/// Extension methods for array manipulation.
///
public static class ArrayExtensions
{
///
/// Efficiently fills an array by repeating a pattern of values.
/// Uses doubling strategy for performance.
///
/// Type of array elements.
/// Array to fill.
/// Pattern of values to repeat throughout the array.
public static void Fill(this T[] destinationArray, params T[] value)
{
int destinationLength = destinationArray.Length;
if (destinationLength == 0)
{
return;
}
int valueLength = value.Length;
// set the initial array value
Array.Copy(value, destinationArray, valueLength);
int arrayToFillHalfLength = destinationLength / 2;
int copyLength;
for (copyLength = valueLength; copyLength < arrayToFillHalfLength; copyLength <<= 1)
{
Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength);
}
Array.Copy(destinationArray, 0, destinationArray, copyLength,
destinationLength - copyLength);
}
}
}