Example #1
0
        public unsafe int GetHashCode(StringSegment str)
        {
            if (_buffer == null || _buffer.Length < str.Length)
            {
                _buffer = new char[Bits.NextPowerOf2(str.Length)];
            }

            for (int i = 0; i < str.Length; i++)
            {
                _buffer[i] = char.ToUpperInvariant(str.String[str.Start + i]);
            }

            fixed(char *p = _buffer)
            {
                return((int)Hashing.XXHash32.CalculateInline((byte *)p, str.Length * sizeof(char)));
            }
        }
Example #2
0
        public unsafe int GetHashCode(StringSegment str)
        {
            if (_buffer == null || _buffer.Length < str.Length)
            {
                _buffer = new char[Bits.NextPowerOf2(str.Length)];
            }

            for (int i = 0; i < str.Length; i++)
            {
                _buffer[i] = char.ToUpperInvariant(str.Buffer[str.Offset + i]);
            }

            fixed(char *p = _buffer)
            {
                //PERF: JIT will remove the corresponding line based on the target architecture using dead code removal.
                if (IntPtr.Size == 4)
                {
                    return((int)Hashing.XXHash32.CalculateInline((byte *)p, str.Length * sizeof(char)));
                }
                return((int)Hashing.XXHash64.CalculateInline((byte *)p, (ulong)str.Length * sizeof(char)));
            }
        }