-
Notifications
You must be signed in to change notification settings - Fork 59
Description
It incorrectly expects the incoming sequence's item type to be Verse.Command when the original code works with its base class Verse.Gizmo. This breaks terribly when an item of such type is encountered in the sequence.
Additionally, it is inefficient in that 1) effectively causes double enumeration of the input sequence, 2) it constantly fetches the command icon instead of loading it once in the static constructor. I suggest you rewrite the function using the iterator protocol. Instead of copying the sequence into a list and then working on this copy make it yield every input item from the input sequence and when the condition is satisfied also yield the new gizmo.
Addendum: it would also be good to avoid creating the new gizmo until the condition is satisfied, using the null conditional assignment so it is created at most once throughout the whole patch. Otherwise it causes unnecessary allocations to be garbage-collected later, in time-critial code.
