-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9292615
commit edc6317
Showing
3 changed files
with
88 additions
and
28 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
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,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.ObjectPool; | ||
|
||
namespace Pchp.Core.Utilities | ||
{ | ||
public class ListPool<T> | ||
{ | ||
sealed class ListPoolPolicy : PooledObjectPolicy<List<T>> | ||
{ | ||
public override List<T> Create() => new List<T>(); | ||
|
||
public override bool Return(List<T> obj) | ||
{ | ||
if (obj.Count > 1024*1024) | ||
{ | ||
return false; | ||
} | ||
|
||
obj.Clear(); | ||
return true; | ||
} | ||
} | ||
|
||
public static readonly ObjectPool<List<T>> Pool = new DefaultObjectPool<List<T>>(new ListPoolPolicy()); | ||
} | ||
} |
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