Skip to content

Commit

Permalink
Have moved to Array.Empty<T> over empty arrays
Browse files Browse the repository at this point in the history
This will use same cache for each type saving memory for larger use cases.
  • Loading branch information
grofit committed Jun 28, 2021
1 parent 86b6c5d commit d387e6f
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/OpenRpg.Cards/Effects/CardEffects.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using OpenRpg.Core.Common;
using OpenRpg.Core.Effects;

Expand All @@ -9,6 +10,6 @@ public class CardEffects : IHasDataId, IHasLocaleDescription, IHasEffects
public int Id { get; set; }
public string NameLocaleId { get; set; }
public string DescriptionLocaleId { get; set; }
public IEnumerable<Effect> Effects { get; set; } = new Effect[0];
public IEnumerable<Effect> Effects { get; set; } = Array.Empty<Effect>();
}
}
5 changes: 3 additions & 2 deletions src/OpenRpg.Cards/Genres/AbilityCard.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using OpenRpg.Cards.Genres.Conventions;
using OpenRpg.Cards.Types;
using OpenRpg.Combat.Abilities;
Expand All @@ -9,7 +10,7 @@ namespace OpenRpg.Cards.Genres
public class AbilityCard : GenericDataCard<Ability>
{
public override int CardType => CardTypes.AbilityCard;
public override IEnumerable<Effect> Effects { get; } = new Effect[0];
public override IEnumerable<Effect> Effects { get; } = Array.Empty<Effect>();

public AbilityCard(Ability ability) : base(ability)
{}
Expand Down
5 changes: 3 additions & 2 deletions src/OpenRpg.Core/Classes/DefaultClassTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using OpenRpg.Core.Effects;
using OpenRpg.Core.Requirements;
Expand All @@ -9,8 +10,8 @@ public class DefaultClassTemplate : IClassTemplate
public int Id { get; set; }
public string NameLocaleId { get; set; }
public string DescriptionLocaleId { get; set; }
public IEnumerable<Effect> Effects { get; set; } = new Effect[0];
public IEnumerable<Requirement> Requirements { get; set; } = new Requirement[0];
public IEnumerable<Effect> Effects { get; set; } = Array.Empty<Effect>();
public IEnumerable<Requirement> Requirements { get; set; } = Array.Empty<Requirement>();
public IClassTemplateVariables Variables { get; set; } = new DefaultClassTemplateVariables();
}
}
3 changes: 2 additions & 1 deletion src/OpenRpg.Core/Effects/Effect.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using OpenRpg.Core.Requirements;

Expand Down Expand Up @@ -25,6 +26,6 @@ public class Effect : IHasRequirements
/// <summary>
/// The applicable requirements for this effect to be active
/// </summary>
public IEnumerable<Requirement> Requirements { get; set; } = new Requirement[0];
public IEnumerable<Requirement> Requirements { get; set; } = Array.Empty<Requirement>();
}
}
3 changes: 2 additions & 1 deletion src/OpenRpg.Core/Modifications/DefaultModification.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using OpenRpg.Core.Effects;

Expand All @@ -6,7 +7,7 @@ namespace OpenRpg.Core.Modifications
public class DefaultModification : IModification
{
public int Id { get; set; }
public IEnumerable<Effect> Effects { get; set; } = new Effect[0];
public IEnumerable<Effect> Effects { get; set; } = Array.Empty<Effect>();
public string NameLocaleId { get; set; }
public string DescriptionLocaleId { get; set; }
public int ModificationType { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion src/OpenRpg.Core/Modifications/ModificationAllowance.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using OpenRpg.Core.Requirements;

Expand All @@ -8,6 +9,6 @@ public class ModificationAllowance : IHasRequirements
public int AmountAllowed { get; set; }
public int ModificationType { get; set; }

public IEnumerable<Requirement> Requirements { get; set; } = new Requirement[0];
public IEnumerable<Requirement> Requirements { get; set; } = Array.Empty<Requirement>();
}
}
5 changes: 3 additions & 2 deletions src/OpenRpg.Core/Races/DefaultRaceTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using OpenRpg.Core.Effects;
using OpenRpg.Core.Requirements;
Expand All @@ -9,8 +10,8 @@ public class DefaultRaceTemplate : IRaceTemplate
public int Id { get; set; }
public string NameLocaleId { get; set; }
public string DescriptionLocaleId { get; set; }
public IEnumerable<Effect> Effects { get; set; } = new Effect[0];
public IEnumerable<Requirement> Requirements { get; set; } = new Requirement[0];
public IEnumerable<Effect> Effects { get; set; } = Array.Empty<Effect>();
public IEnumerable<Requirement> Requirements { get; set; } = Array.Empty<Requirement>();
public IRaceTemplateVariables Variables { get; set; } = new DefaultRaceTemplateVariables();
}
}
3 changes: 2 additions & 1 deletion src/OpenRpg.Items/Extensions/IItemExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRpg.Core.Effects;
Expand Down Expand Up @@ -33,7 +34,7 @@ public static ILootTableEntry GenerateLootTableEntry(this IItem item, float drop
return new DefaultLootTableEntry
{
Item = item,
Requirements = requirements ?? new Requirement[0],
Requirements = requirements ?? Array.Empty<Requirement>(),
Variables = variables
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/OpenRpg.Items/Loot/DefaultLootTableEntry.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using OpenRpg.Core.Requirements;
using OpenRpg.Items.Templates;
Expand All @@ -6,7 +7,7 @@ namespace OpenRpg.Items.Loot
{
public class DefaultLootTableEntry : ILootTableEntry
{
public IEnumerable<Requirement> Requirements { get; set; } = new Requirement[0];
public IEnumerable<Requirement> Requirements { get; set; } = Array.Empty<Requirement>();
public ILootTableEntryVariables Variables { get; set; } = new DefaultLootTableEntryVariables();
public IItem Item { get; set; }
}
Expand Down
7 changes: 4 additions & 3 deletions src/OpenRpg.Items/Templates/DefaultItemTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using OpenRpg.Core.Effects;
using OpenRpg.Core.Modifications;
Expand All @@ -12,9 +13,9 @@ public class DefaultItemTemplate : IItemTemplate
public string NameLocaleId { get; set; }
public string DescriptionLocaleId { get; set; }

public IEnumerable<Requirement> Requirements { get; set; } = new Requirement[0];
public IEnumerable<Effect> Effects { get; set; } = new Effect[0];
public IEnumerable<ModificationAllowance> ModificationAllowances { get; set; } = new ModificationAllowance[0];
public IEnumerable<Requirement> Requirements { get; set; } = Array.Empty<Requirement>();
public IEnumerable<Effect> Effects { get; set; } = Array.Empty<Effect>();
public IEnumerable<ModificationAllowance> ModificationAllowances { get; set; } = Array.Empty<ModificationAllowance>();
public IItemTemplateVariables Variables { get; set; } = new DefaultItemTemplateVariables();
}
}
9 changes: 5 additions & 4 deletions src/OpenRpg.Quests/DefaultQuest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using OpenRpg.Core.Requirements;

Expand All @@ -9,10 +10,10 @@ public class DefaultQuest : IQuest
public string NameLocaleId { get; set; }
public string DescriptionLocaleId { get; set; }
public bool IsRepeatable { get; set; }
public IEnumerable<Requirement> Requirements { get; set; } = new Requirement[0];
public IEnumerable<Objective> Objectives { get; set; } = new Objective[0];
public IEnumerable<Reward> Rewards { get; set; } = new Reward[0];
public IEnumerable<Reward> Gifts { get; set; } = new Reward[0];
public IEnumerable<Requirement> Requirements { get; set; } = Array.Empty<Requirement>();
public IEnumerable<Objective> Objectives { get; set; } = Array.Empty<Objective>();
public IEnumerable<Reward> Rewards { get; set; } = Array.Empty<Reward>();
public IEnumerable<Reward> Gifts { get; set; } = Array.Empty<Reward>();
public IQuestVariables Variables { get; set; } = new DefaultQuestVariables();
}
}

0 comments on commit d387e6f

Please sign in to comment.