Intent of * 200L / 100L
is not any more clearer than * 2
in my opinion. The only reason I can think of why it is done like that is to make sure queue length can grow up to 200 times. There is difference in * 200 / 100
and * 2
such that the first one will result in an overflow exception for 100 times smaller number. For example if it was for byte values, x * 200 / 100
would fail for x==2 but * 2
would fail only if x was as big as 128.
But as Marcelo Cantos pointed out (long)this._array.Length * 200L / 100L
will never overflow so my answer is probably not helping much.
Can it be a 'feature' of ILSpy? Maybe in source code it is just * 2
.
EDIT
After additional investigation it looks that this strange code must be an artefact of some refactoring. I have checked how it's done in List<>
private void EnsureCapacity(int min)
{
if (this._items.Length < min)
{
int num = (this._items.Length == 0) ? 4 : (this._items.Length * 2);
if (num < min)
{
num = min;
}
this.Capacity = num;
}
}
It is as straightforward as you would expect. My guess is that Queue.Enqueue
code was reworked but not fully cleaned up and some strange code resulted out of this change. Most developers assume that Microsoft libraries are perfect and everything has a meaning but it is quite likely that not every line of code is written by a genius :-)