Skip to content

Commit 9077ba0

Browse files
committed
HashCode: Removed unused methods
1 parent 2286c46 commit 9077ba0

File tree

1 file changed

+0
-128
lines changed

1 file changed

+0
-128
lines changed

StandardSocketsHttpHandler/HashCode.cs

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ public struct HashCode
6060
private const uint Prime4 = 668265263U;
6161
private const uint Prime5 = 374761393U;
6262

63-
private uint _v1, _v2, _v3, _v4;
64-
private uint _queue1, _queue2, _queue3;
65-
private uint _length;
66-
6763
private static unsafe uint GenerateGlobalSeed()
6864
{
6965
uint result;
@@ -302,129 +298,5 @@ private static uint MixFinal(uint hash)
302298
hash ^= hash >> 16;
303299
return hash;
304300
}
305-
306-
public void Add<T>(T value)
307-
{
308-
Add(value?.GetHashCode() ?? 0);
309-
}
310-
311-
public void Add<T>(T value, IEqualityComparer<T> comparer)
312-
{
313-
Add(comparer != null ? comparer.GetHashCode(value) : (value?.GetHashCode() ?? 0));
314-
}
315-
316-
private void Add(int value)
317-
{
318-
// The original xxHash works as follows:
319-
// 0. Initialize immediately. We can't do this in a struct (no
320-
// default ctor).
321-
// 1. Accumulate blocks of length 16 (4 uints) into 4 accumulators.
322-
// 2. Accumulate remaining blocks of length 4 (1 uint) into the
323-
// hash.
324-
// 3. Accumulate remaining blocks of length 1 into the hash.
325-
326-
// There is no need for #3 as this type only accepts ints. _queue1,
327-
// _queue2 and _queue3 are basically a buffer so that when
328-
// ToHashCode is called we can execute #2 correctly.
329-
330-
// We need to initialize the xxHash32 state (_v1 to _v4) lazily (see
331-
// #0) nd the last place that can be done if you look at the
332-
// original code is just before the first block of 16 bytes is mixed
333-
// in. The xxHash32 state is never used for streams containing fewer
334-
// than 16 bytes.
335-
336-
// To see what's really going on here, have a look at the Combine
337-
// methods.
338-
339-
var val = (uint)value;
340-
341-
// Storing the value of _length locally shaves of quite a few bytes
342-
// in the resulting machine code.
343-
uint previousLength = _length++;
344-
uint position = previousLength % 4;
345-
346-
// Switch can't be inlined.
347-
348-
if (position == 0)
349-
_queue1 = val;
350-
else if (position == 1)
351-
_queue2 = val;
352-
else if (position == 2)
353-
_queue3 = val;
354-
else // position == 3
355-
{
356-
if (previousLength == 3)
357-
Initialize(out _v1, out _v2, out _v3, out _v4);
358-
359-
_v1 = Round(_v1, _queue1);
360-
_v2 = Round(_v2, _queue2);
361-
_v3 = Round(_v3, _queue3);
362-
_v4 = Round(_v4, val);
363-
}
364-
}
365-
366-
public int ToHashCode()
367-
{
368-
// Storing the value of _length locally shaves of quite a few bytes
369-
// in the resulting machine code.
370-
uint length = _length;
371-
372-
// position refers to the *next* queue position in this method, so
373-
// position == 1 means that _queue1 is populated; _queue2 would have
374-
// been populated on the next call to Add.
375-
uint position = length % 4;
376-
377-
// If the length is less than 4, _v1 to _v4 don't contain anything
378-
// yet. xxHash32 treats this differently.
379-
380-
uint hash = length < 4 ? MixEmptyState() : MixState(_v1, _v2, _v3, _v4);
381-
382-
// _length is incremented once per Add(Int32) and is therefore 4
383-
// times too small (xxHash length is in bytes, not ints).
384-
385-
hash += length * 4;
386-
387-
// Mix what remains in the queue
388-
389-
// Switch can't be inlined right now, so use as few branches as
390-
// possible by manually excluding impossible scenarios (position > 1
391-
// is always false if position is not > 0).
392-
if (position > 0)
393-
{
394-
hash = QueueRound(hash, _queue1);
395-
if (position > 1)
396-
{
397-
hash = QueueRound(hash, _queue2);
398-
if (position > 2)
399-
hash = QueueRound(hash, _queue3);
400-
}
401-
}
402-
403-
hash = MixFinal(hash);
404-
return (int)hash;
405-
}
406-
407-
#pragma warning disable 0809
408-
// Obsolete member 'memberA' overrides non-obsolete member 'memberB'.
409-
// Disallowing GetHashCode and Equals is by design
410-
411-
// * We decided to not override GetHashCode() to produce the hash code
412-
// as this would be weird, both naming-wise as well as from a
413-
// behavioral standpoint (GetHashCode() should return the object's
414-
// hash code, not the one being computed).
415-
416-
// * Even though ToHashCode() can be called safely multiple times on
417-
// this implementation, it is not part of the contract. If the
418-
// implementation has to change in the future we don't want to worry
419-
// about people who might have incorrectly used this type.
420-
421-
[Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes. Use ToHashCode to retrieve the computed hash code.", error: true)]
422-
[EditorBrowsable(EditorBrowsableState.Never)]
423-
public override int GetHashCode() => throw new NotSupportedException(SR.HashCode_HashCodeNotSupported);
424-
425-
[Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes.", error: true)]
426-
[EditorBrowsable(EditorBrowsableState.Never)]
427-
public override bool Equals(object obj) => throw new NotSupportedException(SR.HashCode_EqualityNotSupported);
428-
#pragma warning restore 0809
429301
}
430302
}

0 commit comments

Comments
 (0)