mirror of https://github.com/ppy/osu
Fix multiple enumerations when ordering setting sources
This was not spotted previously, because the base `Attribute` overrides `Equals()` to have semantics similar to structs (per-field equality) by using reflection. That masked the issue when strings were used, and migrating to `LocalisableString` revealed it, as that struct's implementation of equality currently uses instance checks. Whether `LocalisableString.Equals()` is the correct implementation may still be up for discussion, but allowing multiple enumeration is wrong anyway, since the underlying enumerables are live (one especially is a yield iterator, causing new object instances to be allocated).
This commit is contained in:
parent
87b73da73e
commit
528de5869e
|
@ -139,9 +139,12 @@ public static IEnumerable<Drawable> CreateSettingsControls(this object obj)
|
|||
|
||||
public static IEnumerable<(SettingSourceAttribute, PropertyInfo)> GetOrderedSettingsSourceProperties(this object obj)
|
||||
{
|
||||
var original = obj.GetSettingsSourceProperties();
|
||||
var original = obj.GetSettingsSourceProperties().ToArray();
|
||||
|
||||
var orderedRelative = original.Where(attr => attr.Item1.OrderPosition != null).OrderBy(attr => attr.Item1.OrderPosition);
|
||||
var orderedRelative = original
|
||||
.Where(attr => attr.Item1.OrderPosition != null)
|
||||
.OrderBy(attr => attr.Item1.OrderPosition)
|
||||
.ToArray();
|
||||
var unordered = original.Except(orderedRelative);
|
||||
|
||||
return orderedRelative.Concat(unordered);
|
||||
|
|
Loading…
Reference in New Issue