Skip to content

Commit 8c652cc

Browse files
committed
Revert "use HandleCollection for goto targets"
Revert "use List for HandleCollection"
1 parent 83c28f1 commit 8c652cc

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

src/DebugEngineHost.VSCode/VSCode/HandleCollection.cs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,82 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44

5+
using System;
6+
using System.Linq;
57
using System.Collections.Generic;
68

79
namespace Microsoft.DebugEngineHost.VSCode
810
{
911
public sealed class HandleCollection<T>
1012
{
1113
private const int START_HANDLE = 1000;
12-
private List<T> _collection = new List<T>();
1314

14-
public void Clear()
15+
private int _nextHandle;
16+
private Dictionary<int, T> _handleMap;
17+
18+
public HandleCollection()
19+
{
20+
_nextHandle = START_HANDLE;
21+
_handleMap = new Dictionary<int, T>();
22+
}
23+
24+
public void Reset()
1525
{
16-
_collection.Clear();
26+
_nextHandle = START_HANDLE;
27+
_handleMap.Clear();
1728
}
1829

1930
public int Create(T value)
2031
{
21-
_collection.Add(value);
22-
return _collection.Count + START_HANDLE - 1;
32+
var handle = _nextHandle++;
33+
_handleMap[handle] = value;
34+
return handle;
2335
}
2436

2537
public bool TryGet(int handle, out T value)
2638
{
27-
if (handle < 0 || handle - START_HANDLE >= _collection.Count)
39+
if (_handleMap.TryGetValue(handle, out value))
2840
{
29-
value = default;
30-
return false;
41+
return true;
3142
}
32-
33-
value = _collection[handle - START_HANDLE];
34-
return true;
43+
return false;
3544
}
3645

3746
public bool TryGetFirst(out T value)
3847
{
3948
if (IsEmpty)
4049
{
41-
value = default;
50+
value = default(T);
4251
return false;
4352
}
4453

45-
value = _collection[0];
46-
return true;
54+
return TryGet(_handleMap.Keys.Min(), out value);
4755
}
4856

4957
public T this[int handle]
5058
{
5159
get
5260
{
53-
return _collection[handle - START_HANDLE];
61+
T value;
62+
if (!TryGet(handle, out value))
63+
{
64+
throw new ArgumentOutOfRangeException(nameof(handle));
65+
}
66+
67+
return value;
5468
}
5569
}
5670

5771
public bool Remove(int handle)
5872
{
59-
_collection.RemoveAt(handle - START_HANDLE);
60-
return true;
73+
return _handleMap.Remove(handle);
6174
}
6275

6376
public bool IsEmpty
6477
{
6578
get
6679
{
67-
return _collection.Count == 0;
80+
return _handleMap.Count == 0;
6881
}
6982
}
7083
}

src/OpenDebugAD7/AD7DebugSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal sealed class AD7DebugSession : DebugAdapterBase, IDebugPortNotify2, IDe
4242

4343
private readonly DebugEventLogger m_logger;
4444
private readonly Dictionary<string, Dictionary<int, IDebugPendingBreakpoint2>> m_breakpoints;
45-
private readonly HandleCollection<IDebugCodeContext2> m_gotoCodeContexts = new HandleCollection<IDebugCodeContext2>();
45+
private readonly List<IDebugCodeContext2> m_gotoCodeContexts = new List<IDebugCodeContext2>();
4646

4747
private Dictionary<string, IDebugPendingBreakpoint2> m_functionBreakpoints;
4848
private readonly Dictionary<int, ThreadFrameEnumInfo> m_threadFrameEnumInfos = new Dictionary<int, ThreadFrameEnumInfo>();
@@ -314,7 +314,7 @@ public void BeforeContinue()
314314
m_isStepping = false;
315315
m_isStopped = false;
316316
m_variableManager.Reset();
317-
m_frameHandles.Clear();
317+
m_frameHandles.Reset();
318318
m_threadFrameEnumInfos.Clear();
319319
m_gotoCodeContexts.Clear();
320320
}

src/OpenDebugAD7/VariableManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal VariableManager()
2626

2727
internal void Reset()
2828
{
29-
m_variableHandles.Clear();
29+
m_variableHandles.Reset();
3030
}
3131

3232
internal Boolean IsEmpty()

0 commit comments

Comments
 (0)