Merge pull request #4155 from BrzVlad/fix-tls-lmf-addr
[mono-project.git] / mcs / class / dlr / Runtime / Microsoft.Scripting.Core / Utils / Helpers.cs
blobd8827d169686b748341fbc0e183f6caddc7f22bb
1 
2 /* ****************************************************************************
4 * Copyright (c) Microsoft Corporation.
6 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
7 * copy of the license can be found in the License.html file at the root of this distribution. If
8 * you cannot locate the Apache License, Version 2.0, please send an email to
9 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
10 * by the terms of the Apache License, Version 2.0.
12 * You must not remove this notice, or any other, from this software.
15 * ***************************************************************************/
17 #if !FEATURE_CORE_DLR
18 using Microsoft.Scripting.Ast;
19 using Microsoft.Scripting.Utils;
20 #else
21 using System.Linq.Expressions;
22 #endif
24 using System.Collections.Generic;
26 namespace System.Dynamic.Utils {
27 // Miscellaneous helpers that don't belong anywhere else
28 internal static class Helpers {
30 internal static T CommonNode<T>(T first, T second, Func<T, T> parent) where T : class {
31 var cmp = EqualityComparer<T>.Default;
32 if (cmp.Equals(first, second)) {
33 return first;
35 var set = new Set<T>(cmp);
36 for (T t = first; t != null; t = parent(t)) {
37 set.Add(t);
39 for (T t = second; t != null; t = parent(t)) {
40 if (set.Contains(t)) {
41 return t;
44 return null;
47 internal static void IncrementCount<T>(T key, Dictionary<T, int> dict) {
48 int count;
49 dict.TryGetValue(key, out count);
50 dict[key] = count + 1;