Created
January 23, 2018 16:14
-
-
Save KumoKairo/fe7cb6a24135946ba34d7d3e15e10f19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code from TextMeshPro | |
using System; | |
using System.Collections.Generic; | |
namespace TMPro | |
{ | |
public class FastAction<A> | |
{ | |
private LinkedList<Action<A>> delegates = new LinkedList<Action<A>>(); | |
private Dictionary<Action<A>, LinkedListNode<Action<A>>> lookup = new Dictionary<Action<A>, LinkedListNode<Action<A>>>(); | |
public void Add(Action<A> rhs) | |
{ | |
if (this.lookup.ContainsKey(rhs)) | |
return; | |
this.lookup[rhs] = this.delegates.AddLast(rhs); | |
} | |
public void Remove(Action<A> rhs) | |
{ | |
LinkedListNode<Action<A>> node; | |
if (!this.lookup.TryGetValue(rhs, out node)) | |
return; | |
this.lookup.Remove(rhs); | |
this.delegates.Remove(node); | |
} | |
public void Call(A a) | |
{ | |
for (LinkedListNode<Action<A>> linkedListNode = this.delegates.First; linkedListNode != null; linkedListNode = linkedListNode.Next) | |
linkedListNode.Value(a); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment