Skip to content
Artūras Šlajus edited this page Nov 10, 2016 · 2 revisions

SList4<A> is a mutable struct that mimicks IList<A>, but does not allocate heap if it stores 4 or less objects.

As it is a mutable struct, it should be used with care when passing around. For example:

var l = SList4.create(1, 2, 3);
removeLastElement(l);
// l is not actually changed, because we have passed a copy of l into `removeLastElement`.

Where SList excels is for short-lived arrays, like:

// Creates 1 IRxVal, 1 IList and 1 backing array.
var unlockedAllList = F.list(purchasedAll, batchUnlockedAll, fullGamePurchased).anyOf();
// Creates 1 IRxVal and 1 array.
var unlockedAllArray = new [] { purchasedAll, batchUnlockedAll, fullGamePurchased }.anyOf();
// Creates 1 IRxVal. Yay, no garbage!
var unlockedAllSList = SList4.create(purchasedAll, batchUnlockedAll, fullGamePurchased).anyOf();

However make sure, that the methods taking in SLists are defined as:

// No garbage due to boxing.
IRxVal<bool> anyOf<C>(this C vals, bool searchFor=true) where C : IEnumerable<IRxVal<bool>>

Instead of:

// Boxes SList into IEnumerable
IRxVal<bool> anyOf(this IEnumerable<IRxVal<bool>> vals, bool searchFor=true)

More info.