FabianTerhorst / coreclr-module

Old alt:V CoreClr (.NET Core Common Language Runtime) community made module. New: https://github.com/altmp/coreclr-module

Home Page:https://docs.altv.mp/cs/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Server] Suggest using `IEnumerable` for EmitClients instead of array in core implementation

duydang2311 opened this issue · comments

As for now, the Alt.EmitClients takes IPlayer[] as its first argument.
It seems better to prefer IEnumerable<IPlayer> here, so in piece of code like below example can avoid creating a new array with ToArray.

After having a look at the core implementation, I think this change can be made into the core, as a foreach loop can replace the for one https://github.com/FabianTerhorst/coreclr-module/blob/dev/api/AltV.Net/Core.cs#L343.
Plus, this change also doesn't break anything because IEnumerable is array base type.

Example where an extra array must be created to satisfy EmitClients first argument:

public void BroadcastMessage(Predicate<AltIPlayer> predicate, string color, string message)
{
	var players = new LinkedList<AltIPlayer>();
	foreach (var p in Alt.GetAllPlayers())
	{
		if (predicate(p))
		{
			players.AddLast(p);
		}
	}
	Alt.EmitClients(players.ToArray(), "chat.message", color, message);
}

If it's reasonable, I can try working on this.