Skip to content

Commit

Permalink
Revert "Query compilation performance (#430)"
Browse files Browse the repository at this point in the history
This reverts commit 2483303.
  • Loading branch information
smitpatel authored Sep 6, 2019
1 parent 741991b commit c7b4d1d
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 670 deletions.
153 changes: 15 additions & 138 deletions src/EntityFramework/Core/Query/InternalTrees/VarMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@

namespace System.Data.Entity.Core.Query.InternalTrees
{
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

// <summary>
// Helps map one variable to the next.
// </summary>
internal class VarMap : IDictionary<Var, Var>
internal class VarMap : Dictionary<Var, Var>
{
#region public surfaces

private Dictionary<Var, Var> map;
private Dictionary<Var, Var> reverseMap;

internal VarMap GetReverseMap()
{
return new VarMap(reverseMap, map);
}

public bool ContainsValue(Var value)
{
return reverseMap.ContainsKey(value);
var reverseMap = new VarMap();
foreach (var kv in this)
{
Var x;
// On the odd chance that a var is in the varMap more than once, the first one
// is going to be the one we want to use, because it might be the discriminator
// var;
if (!reverseMap.TryGetValue(kv.Value, out x))
{
reverseMap[kv.Value] = kv.Key;
}
}
return reverseMap;
}

public override string ToString()
{
var sb = new StringBuilder();
var separator = string.Empty;

foreach (var v in map.Keys)
foreach (var v in Keys)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}({1},{2})", separator, v.Id, this[v].Id);
separator = ",";
Expand All @@ -42,134 +45,8 @@ public override string ToString()

#endregion

#region IDictionary

public Var this[Var key]
{
get
{
return map[key];
}
set
{
map[key] = value;
}
}

public ICollection<Var> Keys
{
get
{
return map.Keys;
}
}

public ICollection<Var> Values
{
get
{
return map.Values;
}
}

public int Count
{
get
{
return map.Count;
}
}

public bool IsReadOnly
{
get
{
return false;
}
}

public void Add(Var key, Var value)
{
if (!reverseMap.ContainsKey(value))
{
reverseMap.Add(value, key);
}
map.Add(key, value);
}

public void Add(KeyValuePair<Var, Var> item)
{
if (!reverseMap.ContainsKey(item.Value))
{
((IDictionary<Var, Var>)reverseMap).Add(new KeyValuePair<Var, Var>(item.Value, item.Key));
}
((IDictionary<Var, Var>)map).Add(item);
}

public void Clear()
{
map.Clear();
reverseMap.Clear();
}

public bool Contains(KeyValuePair<Var, Var> item)
{
return ((IDictionary<Var, Var>)map).Contains(item);
}

public bool ContainsKey(Var key)
{
return map.ContainsKey(key);
}

public void CopyTo(KeyValuePair<Var, Var>[] array, int arrayIndex)
{
((IDictionary<Var, Var>)map).CopyTo(array, arrayIndex);
}

public IEnumerator<KeyValuePair<Var, Var>> GetEnumerator()
{
return map.GetEnumerator();
}

public bool Remove(Var key)
{
reverseMap.Remove(map[key]);
return map.Remove(key);
}

public bool Remove(KeyValuePair<Var, Var> item)
{
reverseMap.Remove(map[item.Value]);
return ((IDictionary<Var, Var>)map).Remove(item);
}

public bool TryGetValue(Var key, out Var value)
{
return ((IDictionary<Var, Var>)map).TryGetValue(key, out value);
}

IEnumerator IEnumerable.GetEnumerator()
{
return map.GetEnumerator();
}

#endregion

#region constructors

public VarMap()
{
map = new Dictionary<Var, Var>();
reverseMap = new Dictionary<Var, Var>();
}

private VarMap(Dictionary<Var, Var> map, Dictionary<Var, Var> reverseMap)
{
this.map = map;
this.reverseMap = reverseMap;
}

#endregion
}
}
Loading

0 comments on commit c7b4d1d

Please sign in to comment.