1 //===-- FormatCache.cpp ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
16 // Other libraries and framework includes
19 #include "lldb/DataFormatters/FormatCache.h"
22 using namespace lldb_private;
24 FormatCache::Entry::Entry () :
25 m_summary_cached(false),
26 m_synthetic_cached(false),
31 FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) :
32 m_synthetic_cached(false),
35 SetSummary (summary_sp);
38 FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) :
39 m_summary_cached(false),
42 SetSynthetic (synthetic_sp);
45 FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp,lldb::SyntheticChildrenSP synthetic_sp)
47 SetSummary (summary_sp);
48 SetSynthetic (synthetic_sp);
52 FormatCache::Entry::IsSummaryCached ()
54 return m_summary_cached;
58 FormatCache::Entry::IsSyntheticCached ()
60 return m_synthetic_cached;
63 lldb::TypeSummaryImplSP
64 FormatCache::Entry::GetSummary ()
69 lldb::SyntheticChildrenSP
70 FormatCache::Entry::GetSynthetic ()
72 return m_synthetic_sp;
76 FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp)
78 m_summary_cached = true;
79 m_summary_sp = summary_sp;
83 FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp)
85 m_synthetic_cached = true;
86 m_synthetic_sp = synthetic_sp;
89 FormatCache::FormatCache () :
91 m_mutex (Mutex::eMutexTypeRecursive)
92 #ifdef LLDB_CONFIGURATION_DEBUG
93 ,m_cache_hits(0),m_cache_misses(0)
99 FormatCache::GetEntry (const ConstString& type)
101 auto i = m_map.find(type),
105 m_map[type] = FormatCache::Entry();
110 FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
112 Mutex::Locker lock(m_mutex);
113 auto entry = GetEntry(type);
114 if (entry.IsSummaryCached())
116 #ifdef LLDB_CONFIGURATION_DEBUG
119 summary_sp = entry.GetSummary();
122 #ifdef LLDB_CONFIGURATION_DEBUG
130 FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
132 Mutex::Locker lock(m_mutex);
133 auto entry = GetEntry(type);
134 if (entry.IsSyntheticCached())
136 #ifdef LLDB_CONFIGURATION_DEBUG
139 synthetic_sp = entry.GetSynthetic();
142 #ifdef LLDB_CONFIGURATION_DEBUG
145 synthetic_sp.reset();
150 FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
152 Mutex::Locker lock(m_mutex);
153 GetEntry(type).SetSummary(summary_sp);
157 FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
159 Mutex::Locker lock(m_mutex);
160 GetEntry(type).SetSynthetic(synthetic_sp);
164 FormatCache::Clear ()
166 Mutex::Locker lock(m_mutex);