internal static GreenNode?TryGetNode( int kind, GreenNode?child1, GreenNode?child2, GreenNode?child3, GreenNode.NodeFlags flags, out int hash ) { if (CanBeCached(child1, child2, child3)) { GreenStats.ItemCacheable(); int h = hash = GetCacheHash(kind, flags, child1, child2, child3); int idx = h & CacheMask; var e = s_cache[idx]; if ( e.hash == h && e.node != null && e.node.IsCacheEquivalent(kind, flags, child1, child2, child3) ) { GreenStats.CacheHit(); return(e.node); } } else { hash = -1; } return(null); }
private static int GetCacheHash( int kind, GreenNode.NodeFlags flags, GreenNode?child1, GreenNode?child2, GreenNode?child3 ) { int code = (int)(flags) ^ kind; if (child1 != null) { code = Hash.Combine( System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(child1), code ); } if (child2 != null) { code = Hash.Combine( System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(child2), code ); } if (child3 != null) { code = Hash.Combine( System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(child3), code ); } // ensure nonnegative hash return(code & Int32.MaxValue); }
private static int GetCacheHash(int kind, GreenNode.NodeFlags flags, GreenNode child1) { int code = (int)(flags) ^ kind; // the only child is never null code = Hash.Combine(System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(child1), code); // ensure nonnegative hash return(code & Int32.MaxValue); }
private static int GetCacheHash(int kind, GreenNode.NodeFlags flags, GreenNode?child1) { int code = (int)flags ^ kind; // the only child is never null // https://github.com/dotnet/roslyn/issues/41539 code = Hash.Combine(System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(child1 !), code); // ensure nonnegative hash return(code & int.MaxValue); }
private static GreenNode.NodeFlags GetFlags(SyntaxFactoryContext context) { GreenNode.NodeFlags flags = GetFlags(); flags = CSharpSyntaxNode.SetFactoryContext(flags, context); return(flags); }