Skip to content

Commit

Permalink
Revert "use HandleCollection for goto targets"
Browse files Browse the repository at this point in the history
Revert "use List for HandleCollection"
  • Loading branch information
Trass3r committed Nov 6, 2020
1 parent 405a22a commit e207135
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
49 changes: 31 additions & 18 deletions src/DebugEngineHost.VSCode/VSCode/HandleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,82 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.


using System;
using System.Linq;
using System.Collections.Generic;

namespace Microsoft.DebugEngineHost.VSCode
{
public sealed class HandleCollection<T>
{
private const int START_HANDLE = 1000;
private List<T> _collection = new List<T>();

public void Clear()
private int _nextHandle;
private Dictionary<int, T> _handleMap;

public HandleCollection()
{
_nextHandle = START_HANDLE;
_handleMap = new Dictionary<int, T>();
}

public void Reset()
{
_collection.Clear();
_nextHandle = START_HANDLE;
_handleMap.Clear();
}

public int Create(T value)
{
_collection.Add(value);
return _collection.Count + START_HANDLE - 1;
var handle = _nextHandle++;
_handleMap[handle] = value;
return handle;
}

public bool TryGet(int handle, out T value)
{
if (handle < 0 || handle - START_HANDLE >= _collection.Count)
if (_handleMap.TryGetValue(handle, out value))
{
value = default;
return false;
return true;
}

value = _collection[handle - START_HANDLE];
return true;
return false;
}

public bool TryGetFirst(out T value)
{
if (IsEmpty)
{
value = default;
value = default(T);
return false;
}

value = _collection[0];
return true;
return TryGet(_handleMap.Keys.Min(), out value);
}

public T this[int handle]
{
get
{
return _collection[handle - START_HANDLE];
T value;
if (!TryGet(handle, out value))
{
throw new ArgumentOutOfRangeException(nameof(handle));
}

return value;
}
}

public bool Remove(int handle)
{
_collection.RemoveAt(handle - START_HANDLE);
return true;
return _handleMap.Remove(handle);
}

public bool IsEmpty
{
get
{
return _collection.Count == 0;
return _handleMap.Count == 0;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/OpenDebugAD7/AD7DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal sealed class AD7DebugSession : DebugAdapterBase, IDebugPortNotify2, IDe

private readonly DebugEventLogger m_logger;
private readonly Dictionary<string, Dictionary<int, IDebugPendingBreakpoint2>> m_breakpoints;
private readonly HandleCollection<IDebugCodeContext2> m_gotoCodeContexts = new HandleCollection<IDebugCodeContext2>();
private readonly List<IDebugCodeContext2> m_gotoCodeContexts = new List<IDebugCodeContext2>();

private Dictionary<string, IDebugPendingBreakpoint2> m_functionBreakpoints;
private readonly Dictionary<int, ThreadFrameEnumInfo> m_threadFrameEnumInfos = new Dictionary<int, ThreadFrameEnumInfo>();
Expand Down Expand Up @@ -341,7 +341,7 @@ public void BeforeContinue()
m_isStepping = false;
m_isStopped = false;
m_variableManager.Reset();
m_frameHandles.Clear();
m_frameHandles.Reset();
m_threadFrameEnumInfos.Clear();
m_gotoCodeContexts.Clear();
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenDebugAD7/VariableManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal VariableManager()

internal void Reset()
{
m_variableHandles.Clear();
m_variableHandles.Reset();
}

internal Boolean IsEmpty()
Expand Down

0 comments on commit e207135

Please sign in to comment.