FormatCache.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //===-- FormatCache.h ---------------------------------------------*- C++
  2. //-*-===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef LLDB_DATAFORMATTERS_FORMATCACHE_H
  10. #define LLDB_DATAFORMATTERS_FORMATCACHE_H
  11. #include <map>
  12. #include <mutex>
  13. #include "lldb/Utility/ConstString.h"
  14. #include "lldb/lldb-public.h"
  15. namespace lldb_private {
  16. class FormatCache {
  17. private:
  18. struct Entry {
  19. private:
  20. bool m_format_cached : 1;
  21. bool m_summary_cached : 1;
  22. bool m_synthetic_cached : 1;
  23. lldb::TypeFormatImplSP m_format_sp;
  24. lldb::TypeSummaryImplSP m_summary_sp;
  25. lldb::SyntheticChildrenSP m_synthetic_sp;
  26. public:
  27. Entry();
  28. template<typename ImplSP> bool IsCached();
  29. bool IsFormatCached();
  30. bool IsSummaryCached();
  31. bool IsSyntheticCached();
  32. void Get(lldb::TypeFormatImplSP &);
  33. void Get(lldb::TypeSummaryImplSP &);
  34. void Get(lldb::SyntheticChildrenSP &);
  35. void Set(lldb::TypeFormatImplSP);
  36. void Set(lldb::TypeSummaryImplSP);
  37. void Set(lldb::SyntheticChildrenSP);
  38. };
  39. typedef std::map<ConstString, Entry> CacheMap;
  40. CacheMap m_map;
  41. std::recursive_mutex m_mutex;
  42. uint64_t m_cache_hits = 0;
  43. uint64_t m_cache_misses = 0;
  44. Entry &GetEntry(ConstString type);
  45. public:
  46. FormatCache() = default;
  47. template <typename ImplSP> bool Get(ConstString type, ImplSP &format_impl_sp);
  48. void Set(ConstString type, lldb::TypeFormatImplSP &format_sp);
  49. void Set(ConstString type, lldb::TypeSummaryImplSP &summary_sp);
  50. void Set(ConstString type, lldb::SyntheticChildrenSP &synthetic_sp);
  51. void Clear();
  52. uint64_t GetCacheHits() { return m_cache_hits; }
  53. uint64_t GetCacheMisses() { return m_cache_misses; }
  54. };
  55. } // namespace lldb_private
  56. #endif // LLDB_DATAFORMATTERS_FORMATCACHE_H