Checked LINQ queries and collections for inefficiencies.
- Made Array.IndexOf available via extension method. - Made ToHashSet extension method. - Change collections queried often via Contains into sets. - Avoid Count() extension if Count or Length property exist. - Made Count() > 0 checks and variations calls to Any() instead. - Don't call ToList/ToArray if there is no benefit to materializing the sequence. - If the sequence does benefit from materialization, follow this general pattern: - Collection queried often via Contains use ToHashSet to speed up lookups. - Short lived variables use ToList. This is because ToArray requires an extra copy to output the final size. - Collections persisted into fields or for a long time use ToArray to minimize memory overhead.
This commit is contained in:
committed by
RoosterDragon
parent
f5f3747338
commit
82bea961ba
@@ -32,14 +32,14 @@ namespace OpenRA.Graphics
|
||||
var c1 = new HSLColor(c.H, c.S, (byte)Math.Max(rampRange, c.L)).RGB;
|
||||
var c2 = new HSLColor(c.H, c.S, (byte)Math.Max(0, c.L - rampRange)).RGB;
|
||||
var baseIndex = ramp[0];
|
||||
var remapRamp = ramp.Select(r => r - ramp[0]).ToArray();
|
||||
var remapRamp = ramp.Select(r => r - ramp[0]);
|
||||
|
||||
// reversed remapping
|
||||
if (ramp[0] > ramp[15])
|
||||
{
|
||||
baseIndex = ramp[15];
|
||||
for (var i = 15; i > 0; i--)
|
||||
remapRamp = ramp.Select(r => r - ramp[15]).ToArray();
|
||||
remapRamp = ramp.Select(r => r - ramp[15]);
|
||||
}
|
||||
|
||||
remapColors = remapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2)))
|
||||
|
||||
Reference in New Issue
Block a user