FormatCache.cpp revision 8aaa52329ade20107fe28af7085b0a1f395816a8
1//===-- FormatCache.cpp ------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#include "lldb/lldb-python.h" 11 12// C Includes 13 14// C++ Includes 15 16// Other libraries and framework includes 17 18// Project includes 19#include "lldb/DataFormatters/FormatCache.h" 20 21using namespace lldb; 22using namespace lldb_private; 23 24FormatCache::Entry::Entry () : 25m_summary_cached(false), 26m_synthetic_cached(false), 27m_summary_sp(), 28m_synthetic_sp() 29{} 30 31FormatCache::Entry::Entry (const Entry& rhs) : 32m_summary_cached(rhs.m_summary_cached), 33m_synthetic_cached(rhs.m_synthetic_cached), 34m_summary_sp(rhs.m_summary_sp), 35m_synthetic_sp(rhs.m_synthetic_sp) 36{} 37 38FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) : 39m_synthetic_cached(false), 40m_synthetic_sp() 41{ 42 SetSummary (summary_sp); 43} 44 45FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) : 46m_summary_cached(false), 47m_summary_sp() 48{ 49 SetSynthetic (synthetic_sp); 50} 51 52FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp,lldb::SyntheticChildrenSP synthetic_sp) 53{ 54 SetSummary (summary_sp); 55 SetSynthetic (synthetic_sp); 56} 57 58FormatCache::Entry& FormatCache::Entry::operator= (const Entry& rhs) 59{ 60 if (this == &rhs) 61 return *this; 62 63 m_summary_cached = rhs.m_summary_cached; 64 m_synthetic_cached = rhs.m_synthetic_cached; 65 m_summary_sp = rhs.m_summary_sp; 66 m_synthetic_sp = rhs.m_synthetic_sp; 67 return *this; 68} 69 70bool 71FormatCache::Entry::IsSummaryCached () 72{ 73 return m_summary_cached; 74} 75 76bool 77FormatCache::Entry::IsSyntheticCached () 78{ 79 return m_synthetic_cached; 80} 81 82lldb::TypeSummaryImplSP 83FormatCache::Entry::GetSummary () 84{ 85 return m_summary_sp; 86} 87 88lldb::SyntheticChildrenSP 89FormatCache::Entry::GetSynthetic () 90{ 91 return m_synthetic_sp; 92} 93 94void 95FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp) 96{ 97 m_summary_cached = true; 98 m_summary_sp = summary_sp; 99} 100 101void 102FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp) 103{ 104 m_synthetic_cached = true; 105 m_synthetic_sp = synthetic_sp; 106} 107 108FormatCache::FormatCache () : 109m_map(), 110m_mutex (Mutex::eMutexTypeRecursive) 111#ifdef LLDB_CONFIGURATION_DEBUG 112,m_cache_hits(0),m_cache_misses(0) 113#endif 114{ 115} 116 117FormatCache::Entry& 118FormatCache::GetEntry (const ConstString& type) 119{ 120 auto i = m_map.find(type), 121 e = m_map.end(); 122 if (i != e) 123 return i->second; 124 m_map[type] = FormatCache::Entry(); 125 return m_map[type]; 126} 127 128bool 129FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) 130{ 131 Mutex::Locker lock(m_mutex); 132 auto entry = GetEntry(type); 133 if (entry.IsSummaryCached()) 134 { 135#ifdef LLDB_CONFIGURATION_DEBUG 136 m_cache_hits++; 137#endif 138 summary_sp = entry.GetSummary(); 139 return true; 140 } 141#ifdef LLDB_CONFIGURATION_DEBUG 142 m_cache_misses++; 143#endif 144 summary_sp.reset(); 145 return false; 146} 147 148bool 149FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp) 150{ 151 Mutex::Locker lock(m_mutex); 152 auto entry = GetEntry(type); 153 if (entry.IsSyntheticCached()) 154 { 155#ifdef LLDB_CONFIGURATION_DEBUG 156 m_cache_hits++; 157#endif 158 synthetic_sp = entry.GetSynthetic(); 159 return true; 160 } 161#ifdef LLDB_CONFIGURATION_DEBUG 162 m_cache_misses++; 163#endif 164 synthetic_sp.reset(); 165 return false; 166} 167 168void 169FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) 170{ 171 Mutex::Locker lock(m_mutex); 172 GetEntry(type).SetSummary(summary_sp); 173} 174 175void 176FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp) 177{ 178 Mutex::Locker lock(m_mutex); 179 GetEntry(type).SetSynthetic(synthetic_sp); 180} 181 182void 183FormatCache::Clear () 184{ 185 Mutex::Locker lock(m_mutex); 186 m_map.clear(); 187} 188 189