diff --git a/Projects/Server/Utilities/Utility.cs b/Projects/Server/Utilities/Utility.cs index 30f25b577..6881fb03d 100644 --- a/Projects/Server/Utilities/Utility.cs +++ b/Projects/Server/Utilities/Utility.cs @@ -1554,5 +1554,32 @@ namespace Server min = date.Minute; sec = date.Second; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T[] Combine(this IList source, bool pooled = false, params IList[] arrays) + { + var totalLength = source.Count; + foreach (var arr in arrays) + { + totalLength += arr.Count; + } + + if (totalLength == 0) + { + return Array.Empty(); + } + + var combined = pooled ? STArrayPool.Shared.Rent(totalLength) : new T[totalLength]; + + source.CopyTo(combined, 0); + var position = source.Count; + foreach (var arr in arrays) + { + arr.CopyTo(combined, position); + position += arr.Count; + } + + return combined; + } } }