ArrayExecutionContext.cs 773 B

123456789101112131415161718192021222324
  1. using System.Collections.Generic;
  2. using System.Threading;
  3. namespace Jint.Native.Array
  4. {
  5. /// <summary>
  6. /// Helper to cache common data structures needed in array access on a per thread basis.
  7. /// </summary>
  8. internal class ArrayExecutionContext
  9. {
  10. // cache key container for array iteration for less allocations
  11. private static readonly ThreadLocal<ArrayExecutionContext> _executionContext = new ThreadLocal<ArrayExecutionContext>(() => new ArrayExecutionContext());
  12. private List<uint> _keyCache;
  13. private ArrayExecutionContext()
  14. {
  15. }
  16. public List<uint> KeyCache => _keyCache = _keyCache ?? new List<uint>();
  17. public static ArrayExecutionContext Current => _executionContext.Value;
  18. }
  19. }