Skip to content

Commit

Permalink
bring back START_HANDLE
Browse files Browse the repository at this point in the history
  • Loading branch information
Trass3r committed Sep 10, 2020
1 parent 558af5f commit b553574
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/DebugEngineHost.VSCode/VSCode/HandleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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()
Expand All @@ -18,18 +19,18 @@ public void Clear()
public int Create(T value)
{
_collection.Add(value);
return _collection.Count - 1;
return _collection.Count + START_HANDLE - 1;
}

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

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

Expand All @@ -49,13 +50,13 @@ public T this[int handle]
{
get
{
return _collection[handle];
return _collection[handle - START_HANDLE];
}
}

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

Expand Down

0 comments on commit b553574

Please sign in to comment.