protected static NodeInfo CreateInstance(Address a, IList tas, TransportAddress ta)
{
NodeInfo result = null;
var ni_cache = Interlocked.Exchange <WeakValueTable <int, NodeInfo> >(ref _cache, null);
if (ni_cache != null)
{
try {
//Set up the key:
_cache_key._done_hash = false;
_cache_key._address = a;
if (tas == null)
{
if (ta == null)
{
_cache_key._tas = EmptyTas;
}
else
{
_ta_list[0] = ta;
_cache_key._tas = _ta_list;
}
}
else
{
_cache_key._tas = tas;
}
result = ni_cache.GetValue(_cache_key.GetHashCode());
if (!_cache_key.Equals(result))
{
//This may look weird, but we are using a NodeInfo as a key
//to lookup NodeInfos, this will allow us to only keep one
//identical NodeInfo in scope at a time.
if (ta == null)
{
//Note, if ta == null that implies tas is not null
result = new NodeInfo(a, tas);
}
else
{
result = new NodeInfo(a, ta);
}
ni_cache.Replace(result.GetHashCode(), result);
}
} finally {
Interlocked.Exchange <WeakValueTable <int, NodeInfo> >(ref _cache, ni_cache);
}
}
else if (ta == null)
{
//Note, if ta == null that implies tas is not null
result = new NodeInfo(a, tas);
}
else
{
result = new NodeInfo(a, ta);
}
return(result);
}