Software Development
Code review challenge – The concurrent dictionary refactoring
In a recent code review, I had modified the following code:
_freeSegments.AddOrUpdate(memoryDataForPointer.SizeInBytes, x => { var newQueue = new ConcurrentQueue<AllocatedMemoryData>>(); newQueue.Enqueue(memoryDataForPointer); return newQueue; }, (x, queue) => { queue.Enqueue(memoryDataForPointer); return queue; });
Into this code:
var q = _freeSegments.GetOrAdd(memoryDataForPointer.SizeInBytes, size => new ConcurrentQueue<AllocatedMemoryData>()); q.Enqueue(memoryDataForPointer);
Can you tell me why?
Reference: | Code review challenge – The concurrent dictionary refactoring from our NCG partner Oren Eini at the Ayende @ Rahien blog. |