InlineCachePointerArray.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace Js
  7. {
  8. template<class T>
  9. class InlineCachePointerArray
  10. {
  11. public:
  12. typename FieldWithBarrier(Field(T*)*) inlineCaches;
  13. private:
  14. #if DBG
  15. Field(uint) inlineCacheCount;
  16. #endif
  17. public:
  18. InlineCachePointerArray<T>();
  19. private:
  20. void EnsureInlineCaches(Recycler *const recycler, FunctionBody *const functionBody);
  21. public:
  22. T *GetInlineCache(FunctionBody *const functionBody, const uint index) const;
  23. T *GetInlineCache(const uint index) const;
  24. bool HasInlineCaches() const;
  25. void SetInlineCache(
  26. Recycler *const recycler,
  27. FunctionBody *const functionBody,
  28. const uint index,
  29. T *const inlineCache);
  30. void Reset();
  31. template <class Fn>
  32. void Map(Fn fn, uint count) const
  33. {
  34. if (NULL != inlineCaches)
  35. {
  36. for (uint i =0; i < count; i++)
  37. {
  38. T* inlineCache = inlineCaches[i];
  39. if (inlineCache != NULL)
  40. {
  41. fn(inlineCache);
  42. }
  43. }
  44. }
  45. };
  46. PREVENT_COPY(InlineCachePointerArray)
  47. };
  48. }