Xamarin Public Jenkins (auto-signing) e79aa3c0ed Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
2016-08-03 10:59:49 +00:00

58 lines
1.8 KiB
C#

//------------------------------------------------------------------------------
// <copyright file="CompatibleComparer.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* This class is used to create hashcodes that are Everett Compatible.
*
* Copyright (c) 2004 Microsoft Corporation
*/
namespace System.Collections.Specialized {
using Microsoft.Win32;
using System.Collections;
using System.Runtime.Serialization;
using System.Globalization;
internal class BackCompatibleStringComparer : IEqualityComparer {
static internal IEqualityComparer Default = new BackCompatibleStringComparer();
internal BackCompatibleStringComparer() {
}
//This comes from VS# 434837 and is specifically written to get backcompat
public static int GetHashCode(string obj) {
unsafe {
fixed (char* src = obj) {
int hash = 5381;
int c;
char* szStr = src;
while ((c = *szStr) != 0) {
hash = ((hash << 5) + hash) ^ c;
++szStr;
}
return hash;
}
}
}
bool IEqualityComparer.Equals(Object a, Object b) {
return Object.Equals(a, b);
}
public virtual int GetHashCode(Object o) {
String obj = o as string;
if (obj == null) {
return o.GetHashCode();
}
return BackCompatibleStringComparer.GetHashCode(obj);
}
}
}