Skip to content

Commit

Permalink
feat: Replaces params array with params ReadOnlySpan (#2125)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman authored Feb 14, 2025
1 parent 90059c5 commit 279b10d
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Projects/Server/Items/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public virtual bool TryDropItem(Mobile from, Item dropped, bool sendFullMessage,
return false;
}

public virtual bool TryDropItems(Mobile from, bool sendFullMessage, params Item[] droppedItems)
public virtual bool TryDropItems(Mobile from, bool sendFullMessage, params ReadOnlySpan<Item> droppedItems)
{
var dropItems = new List<Item>();
var stackItems = new List<ItemStackEntry>();
Expand Down
6 changes: 3 additions & 3 deletions Projects/Server/Regions/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class Region : IComparable<Region>, IValueLinkListNode<Region>
public const int MinZ = sbyte.MinValue;
public const int MaxZ = sbyte.MaxValue + 1;

public Region(string name, Map map, int priority, params Rectangle2D[] area) : this(
public Region(string name, Map map, int priority, params ReadOnlySpan<Rectangle2D> area) : this(
name,
map,
priority,
Expand All @@ -147,7 +147,7 @@ public Region(string name, Map map, int priority, params Rectangle3D[] area) : t
public Region(string name, Map map, Region parent, int priority, params Rectangle3D[] area) : this(name, map, parent, area) =>
Priority = priority;

public Region(string name, Map map, Region parent, params Rectangle2D[] area) : this(
public Region(string name, Map map, Region parent, params ReadOnlySpan<Rectangle2D> area) : this(
name,
map,
parent,
Expand Down Expand Up @@ -314,7 +314,7 @@ public static Region Find(Point3D p, Map map)
public static Rectangle3D ConvertTo3D(Rectangle2D rect) =>
new(new Point3D(rect.Start, MinZ), new Point3D(rect.End, MaxZ));

public static Rectangle3D[] ConvertTo3D(Rectangle2D[] rects)
public static Rectangle3D[] ConvertTo3D(ReadOnlySpan<Rectangle2D> rects)
{
var ret = new Rectangle3D[rects.Length];

Expand Down
8 changes: 4 additions & 4 deletions Projects/Server/Utilities/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ public static void RandomSample<T>(this T[] source, int count, List<T> dest)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T RandomList<T>(params T[] list) => list.RandomElement();
public static T RandomList<T>(params ReadOnlySpan<T> list) => list.RandomElement();

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T RandomElement<T>(this ReadOnlySpan<T> list) => list.Length == 0 ? default : list[Random(list.Length)];
Expand Down Expand Up @@ -1305,15 +1305,15 @@ out int sec
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Combine<T>(this IList<T> source, params IList<T>[] arrays) =>
public static T[] Combine<T>(this IList<T> source, params ReadOnlySpan<IList<T>> arrays) =>
source.Combine(false, arrays);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] CombinePooled<T>(this IList<T> source, params IList<T>[] arrays) =>
public static T[] CombinePooled<T>(this IList<T> source, params ReadOnlySpan<IList<T>> arrays) =>
source.Combine(true, arrays);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Combine<T>(this IList<T> source, bool pooled, params IList<T>[] arrays)
public static T[] Combine<T>(this IList<T> source, bool pooled, params ReadOnlySpan<IList<T>> arrays)
{
var totalLength = source.Count;
foreach (var arr in arrays)
Expand Down
4 changes: 2 additions & 2 deletions Projects/UOContent/Engines/Spawners/BaseSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public BaseSpawner(string spawnedName) : this(

public BaseSpawner(
int amount, int minDelay, int maxDelay, int team, int homeRange,
params string[] spawnedNames
params ReadOnlySpan<string> spawnedNames
) : this(
amount,
TimeSpan.FromMinutes(minDelay),
Expand All @@ -99,7 +99,7 @@ params string[] spawnedNames

public BaseSpawner(
int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange,
params string[] spawnedNames
params ReadOnlySpan<string> spawnedNames
) : base(0x1f13)
{
_guid = Guid.NewGuid();
Expand Down
4 changes: 2 additions & 2 deletions Projects/UOContent/Engines/Spawners/ProximitySpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public ProximitySpawner(
[Constructible(AccessLevel.Developer)]
public ProximitySpawner(
int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange,
params string[] spawnedNames
params ReadOnlySpan<string> spawnedNames
) : base(amount, minDelay, maxDelay, team, homeRange, spawnedNames)
{
}

[Constructible(AccessLevel.Developer)]
public ProximitySpawner(
int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange, int triggerRange,
TextDefinition spawnMessage, bool instantFlag, params string[] spawnedNames
TextDefinition spawnMessage, bool instantFlag, params ReadOnlySpan<string> spawnedNames
) : base(amount, minDelay, maxDelay, team, homeRange, spawnedNames)
{
TriggerRange = triggerRange;
Expand Down
4 changes: 2 additions & 2 deletions Projects/UOContent/Engines/Spawners/RegionSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public RegionSpawner(string spawnedName) : base(spawnedName)
[Constructible(AccessLevel.Developer)]
public RegionSpawner(
int amount, int minDelay, int maxDelay, int team, int homeRange,
params string[] spawnedNames
params ReadOnlySpan<string> spawnedNames
) : this(
amount,
TimeSpan.FromMinutes(minDelay),
Expand All @@ -57,7 +57,7 @@ params string[] spawnedNames
[Constructible(AccessLevel.Developer)]
public RegionSpawner(
int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange,
params string[] spawnedNames
params ReadOnlySpan<string> spawnedNames
) : base(amount, minDelay, maxDelay, team, homeRange, spawnedNames)
{
}
Expand Down
4 changes: 2 additions & 2 deletions Projects/UOContent/Engines/Spawners/Spawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Spawner(string spawnedName) : base(spawnedName)
[Constructible(AccessLevel.Developer)]
public Spawner(
int amount, int minDelay, int maxDelay, int team, int homeRange,
params string[] spawnedNames
params ReadOnlySpan<string> spawnedNames
) : this(
amount,
TimeSpan.FromMinutes(minDelay),
Expand All @@ -36,7 +36,7 @@ params string[] spawnedNames
[Constructible(AccessLevel.Developer)]
public Spawner(
int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange,
params string[] spawnedNames
params ReadOnlySpan<string> spawnedNames
) : base(amount, minDelay, maxDelay, team, homeRange, spawnedNames)
{
}
Expand Down
2 changes: 1 addition & 1 deletion Projects/UOContent/Gumps/AdminGump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ public AdminGump(

public void AddPageButton(
int x, int y, int buttonID, string text, AdminGumpPage page,
params AdminGumpPage[] subPages
params ReadOnlySpan<AdminGumpPage> subPages
)
{
var isSelection = m_PageType == page;
Expand Down
4 changes: 2 additions & 2 deletions Projects/UOContent/Items/Misc/FlippableAddonAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Server.Items;
[AttributeUsage(AttributeTargets.Class)]
public class FlippableAddonAttribute : Attribute
{
private static readonly string m_MethodName = "Flip";
private const string MethodName = "Flip";

private static readonly Type[] m_Params =
{
Expand All @@ -26,7 +26,7 @@ public virtual void Flip(Mobile from, Item addon)

try
{
var flipMethod = addon.GetType().GetMethod(m_MethodName, m_Params);
var flipMethod = addon.GetType().GetMethod(MethodName, m_Params);

if (flipMethod == null)
{
Expand Down
4 changes: 2 additions & 2 deletions Projects/UOContent/Misc/InhumanSpeech.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ public string ConstructSentence(int wordCount)
return sentence.ToString();
}

public void SayRandomTranslate(Mobile mob, params string[] sentancesInEnglish)
public void SayRandomTranslate(Mobile mob, params ReadOnlySpan<string> sentencesInEnglish)
{
SaySentance(mob, Utility.RandomMinMax(2, 3));
mob.Say(sentancesInEnglish.RandomElement());
mob.Say(sentencesInEnglish.RandomElement());
}

private string GetRandomResponseWord(List<string> keywordsFound)
Expand Down
8 changes: 4 additions & 4 deletions Projects/UOContent/Misc/Loot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,15 @@ public static T Construct<T>(Type type) where T : Item
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Item Construct(params Type[] types) => Construct<Item>(types.RandomElement());
public static Item Construct(params ReadOnlySpan<Type> types) => Construct<Item>(types.RandomElement());

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Construct<T>(params Type[] types) where T : Item => Construct<T>(types.RandomElement());
public static T Construct<T>(params ReadOnlySpan<Type> types) where T : Item => Construct<T>(types.RandomElement());

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Item Construct(Type[] types, int index) => Construct<Item>(types, index);
public static Item Construct(ReadOnlySpan<Type> types, int index) => Construct<Item>(types, index);

public static T Construct<T>(Type[] types, int index) where T : Item
public static T Construct<T>(ReadOnlySpan<Type> types, int index) where T : Item
{
if (index >= 0 && index < types.Length)
{
Expand Down
8 changes: 4 additions & 4 deletions Projects/UOContent/Misc/Weather.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public class Weather
private int m_Stage;

public Weather(
Map facet, Rectangle2D[] area, int temperature, int chanceOfPercipitation, int chanceOfExtremeTemperature,
Map facet, Rectangle2D[] area, int temperature, int chanceOfPrecipitation, int chanceOfExtremeTemperature,
TimeSpan interval
)
{
Facet = facet;
Area = area;
Temperature = temperature;
ChanceOfPercipitation = chanceOfPercipitation;
ChanceOfPrecipitation = chanceOfPrecipitation;
ChanceOfExtremeTemperature = chanceOfExtremeTemperature;

var list = GetWeatherList(facet);
Expand All @@ -42,7 +42,7 @@ TimeSpan interval

public int Temperature { get; set; }

public int ChanceOfPercipitation { get; set; }
public int ChanceOfPrecipitation { get; set; }

public int ChanceOfExtremeTemperature { get; set; }

Expand Down Expand Up @@ -298,7 +298,7 @@ public virtual void OnTick()
{
if (m_Stage == 0)
{
m_Active = ChanceOfPercipitation > Utility.Random(100);
m_Active = ChanceOfPrecipitation > Utility.Random(100);
m_ExtremeTemperature = ChanceOfExtremeTemperature > Utility.Random(100);

if (MoveSpeed > 0)
Expand Down
3 changes: 2 additions & 1 deletion Projects/UOContent/Mobiles/AI/HealerAI.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Server.Spells;
using Server.Spells.First;
using Server.Spells.Fourth;
Expand Down Expand Up @@ -132,7 +133,7 @@ private void ProcessTarget(Target targ, NeedDelegate[] func)
}
}

private Mobile Find(params NeedDelegate[] funcs)
private Mobile Find(params ReadOnlySpan<NeedDelegate> funcs)
{
if (m_Mobile.Deleted)
{
Expand Down
6 changes: 3 additions & 3 deletions Projects/UOContent/Multis/ComponentVerification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ private int[] CreateTable(int length)
return table;
}

private void LoadItems(string path, params string[] itemColumns)
private void LoadItems(string path, params ReadOnlySpan<string> itemColumns)
{
LoadSpreadsheet(m_ItemTable, path, itemColumns);
}

private void LoadMultis(string path, params string[] multiColumns)
private void LoadMultis(string path, params ReadOnlySpan<string> multiColumns)
{
LoadSpreadsheet(m_MultiTable, path, multiColumns);
}

private void LoadSpreadsheet(int[] table, string path, params string[] tileColumns)
private void LoadSpreadsheet(int[] table, string path, params ReadOnlySpan<string> tileColumns)
{
var ss = new Spreadsheet(path);

Expand Down
4 changes: 2 additions & 2 deletions Projects/UOContent/Regions/BaseRegion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BaseRegion : Region
private static readonly List<Rectangle3D> m_RectBuffer1 = new();
private static readonly List<Rectangle3D> m_RectBuffer2 = new();

public BaseRegion(string name, Map map, int priority, params Rectangle2D[] area) : base(name, map, priority, area)
public BaseRegion(string name, Map map, int priority, params ReadOnlySpan<Rectangle2D> area) : base(name, map, priority, area)
{
}

Expand All @@ -26,7 +26,7 @@ public BaseRegion(string name, Map map, Region parent, int priority, params Rect
{
}

public BaseRegion(string name, Map map, Region parent, params Rectangle2D[] area) : base(name, map, parent, area)
public BaseRegion(string name, Map map, Region parent, params ReadOnlySpan<Rectangle2D> area) : base(name, map, parent, area)
{
}

Expand Down

0 comments on commit 279b10d

Please sign in to comment.