[mlir][py] Enable loading only specified dialects during creation. (#121421)
[llvm-project.git] / lldb / source / DataFormatters / FormatCache.cpp
blob6c83b36e79deaaa6f6c76d6825b89c36dd408733
1 //===-- FormatCache.cpp ---------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
12 #include "lldb/DataFormatters/FormatCache.h"
14 using namespace lldb;
15 using namespace lldb_private;
17 FormatCache::Entry::Entry()
18 : m_format_cached(false), m_summary_cached(false),
19 m_synthetic_cached(false) {}
21 bool FormatCache::Entry::IsFormatCached() { return m_format_cached; }
23 bool FormatCache::Entry::IsSummaryCached() { return m_summary_cached; }
25 bool FormatCache::Entry::IsSyntheticCached() { return m_synthetic_cached; }
27 void FormatCache::Entry::Get(lldb::TypeFormatImplSP &retval) {
28 retval = m_format_sp;
31 void FormatCache::Entry::Get(lldb::TypeSummaryImplSP &retval) {
32 retval = m_summary_sp;
35 void FormatCache::Entry::Get(lldb::SyntheticChildrenSP &retval) {
36 retval = m_synthetic_sp;
39 void FormatCache::Entry::Set(lldb::TypeFormatImplSP format_sp) {
40 m_format_cached = true;
41 m_format_sp = format_sp;
44 void FormatCache::Entry::Set(lldb::TypeSummaryImplSP summary_sp) {
45 m_summary_cached = true;
46 m_summary_sp = summary_sp;
49 void FormatCache::Entry::Set(lldb::SyntheticChildrenSP synthetic_sp) {
50 m_synthetic_cached = true;
51 m_synthetic_sp = synthetic_sp;
54 namespace lldb_private {
56 template<> bool FormatCache::Entry::IsCached<lldb::TypeFormatImplSP>() {
57 return IsFormatCached();
59 template<> bool FormatCache::Entry::IsCached<lldb::TypeSummaryImplSP> () {
60 return IsSummaryCached();
62 template<> bool FormatCache::Entry::IsCached<lldb::SyntheticChildrenSP>() {
63 return IsSyntheticCached();
66 } // namespace lldb_private
68 template <typename ImplSP>
69 bool FormatCache::Get(ConstString type, ImplSP &format_impl_sp) {
70 std::lock_guard<std::recursive_mutex> guard(m_mutex);
71 auto entry = m_entries[type];
72 if (entry.IsCached<ImplSP>()) {
73 m_cache_hits++;
74 entry.Get(format_impl_sp);
75 return true;
77 m_cache_misses++;
78 format_impl_sp.reset();
79 return false;
82 /// Explicit instantiations for the three types.
83 /// \{
84 template bool
85 FormatCache::Get<lldb::TypeFormatImplSP>(ConstString, lldb::TypeFormatImplSP &);
86 template bool
87 FormatCache::Get<lldb::TypeSummaryImplSP>(ConstString,
88 lldb::TypeSummaryImplSP &);
89 template bool
90 FormatCache::Get<lldb::SyntheticChildrenSP>(ConstString,
91 lldb::SyntheticChildrenSP &);
92 /// \}
94 void FormatCache::Set(ConstString type, lldb::TypeFormatImplSP &format_sp) {
95 std::lock_guard<std::recursive_mutex> guard(m_mutex);
96 m_entries[type].Set(format_sp);
99 void FormatCache::Set(ConstString type, lldb::TypeSummaryImplSP &summary_sp) {
100 std::lock_guard<std::recursive_mutex> guard(m_mutex);
101 m_entries[type].Set(summary_sp);
104 void FormatCache::Set(ConstString type,
105 lldb::SyntheticChildrenSP &synthetic_sp) {
106 std::lock_guard<std::recursive_mutex> guard(m_mutex);
107 m_entries[type].Set(synthetic_sp);
110 void FormatCache::Clear() {
111 std::lock_guard<std::recursive_mutex> guard(m_mutex);
112 m_entries.clear();