using Jint.Native; using Jint.Runtime; 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, JsString.Empty, false, null); } public Reference Rent(JsValue baseValue, JsValue name, bool strict, JsValue? thisValue) { return _pool.Allocate().Reassign(baseValue, name, strict, thisValue); } public void Return(Reference? reference) { if (reference == null) { return; } _pool.Free(reference); } }