using Jint.Native; using Jint.Runtime.References; namespace Jint.Pooling { /// /// Cache reusable instances as we allocate them a lot. /// internal sealed class ReferencePool { private const int PoolSize = 10; private readonly ObjectPool _pool; public ReferencePool() { _pool = new ObjectPool(Factory, PoolSize); } private static Reference Factory() { return new Reference(JsValue.Undefined, string.Empty, false); } public Reference Rent(JsValue baseValue, in Key name, bool strict) { return _pool.Allocate().Reassign(baseValue, name, strict); } public void Return(Reference reference) { if (reference == null) { return; } _pool.Free(reference);; } } }