-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List pool usage extended to other valiable places
- Loading branch information
Showing
10 changed files
with
156 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using NUnit.Framework; | ||
using System.Collections.Generic; | ||
using VContainer.Internal; | ||
|
||
namespace VContainer.Tests | ||
{ | ||
[TestFixture] | ||
public class ListPoolTests | ||
{ | ||
[Test] | ||
public void Get_ShouldReturnNewList_WhenPoolIsEmpty() | ||
{ | ||
var buffer = ListPool<int>.Get(); | ||
|
||
Assert.IsNotNull(buffer); | ||
Assert.AreEqual(0, buffer.Count); | ||
} | ||
|
||
[Test] | ||
public void Get_ShouldReturnListFromPool_WhenPoolIsNotEmpty() | ||
{ | ||
var initialBuffer = ListPool<int>.Get(); | ||
ListPool<int>.Release(initialBuffer); | ||
|
||
var buffer = ListPool<int>.Get(); | ||
Assert.AreSame(initialBuffer, buffer); | ||
} | ||
|
||
[Test] | ||
public void Release_ShouldClearAndReturnListToPool() | ||
{ | ||
var buffer = ListPool<int>.Get(); | ||
buffer.Add(1); | ||
|
||
ListPool<int>.Release(buffer); | ||
Assert.AreEqual(0, buffer.Count); | ||
} | ||
|
||
[Test] | ||
public void BufferScope_ShouldReleaseBuffer_WhenDisposed() | ||
{ | ||
List<int> buffer; | ||
using (ListPool<int>.Get(out buffer)) | ||
{ | ||
buffer.Add(1); | ||
} | ||
|
||
Assert.AreEqual(0, buffer.Count); | ||
} | ||
|
||
[Test] | ||
public void Get_And_Release_MultipleBuffers() | ||
{ | ||
var buffer1 = ListPool<int>.Get(); | ||
var buffer2 = ListPool<int>.Get(); | ||
|
||
ListPool<int>.Release(buffer1); | ||
ListPool<int>.Release(buffer2); | ||
|
||
var bufferFromPool1 = ListPool<int>.Get(); | ||
var bufferFromPool2 = ListPool<int>.Get(); | ||
|
||
Assert.AreNotSame(bufferFromPool1, bufferFromPool2); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters