From 0fdc6a7e4b7d8463a72c9a021ebf8feb7e17a0b9 Mon Sep 17 00:00:00 2001 From: FPtje Date: Thu, 5 Nov 2015 19:32:18 +0100 Subject: Cache extension with a boolean --- windirstat/item.cpp | 8 +++++--- windirstat/item.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'windirstat') diff --git a/windirstat/item.cpp b/windirstat/item.cpp index f71f5be..0219fe7 100644 --- a/windirstat/item.cpp +++ b/windirstat/item.cpp @@ -909,7 +909,7 @@ CString CItem::GetName() const CString CItem::GetExtension() const { - if (m_extension != "") + if (m_extension_cached) return m_extension; CString ext; @@ -942,6 +942,7 @@ CString CItem::GetExtension() const } m_extension = ext; + m_extension_cached = true; return ext; } @@ -1610,9 +1611,10 @@ void CItem::RecurseCollectExtensionData(CExtensionData *ed) { GetWDSApp()->PeriodicalUpdateRamUsage(); - if(IsLeaf(GetType())) + auto type = GetType(); + if(IsLeaf(type)) { - if(GetType() == IT_FILE) + if(type == IT_FILE) { CString ext = GetExtension(); SExtensionRecord r; diff --git a/windirstat/item.h b/windirstat/item.h index e9778e9..4bcd4e3 100644 --- a/windirstat/item.h +++ b/windirstat/item.h @@ -62,7 +62,7 @@ enum ITEMTYPE }; // Whether an item type is a leaf type -inline bool IsLeaf(ITEMTYPE t) { return t == IT_FILE || t == IT_FREESPACE || t == IT_UNKNOWN; } +inline bool IsLeaf(ITEMTYPE t) { return ((t == IT_FILE) | (t == IT_FREESPACE) | (t == IT_UNKNOWN)); } // Compare FILETIMEs inline bool operator< (const FILETIME& t1, const FILETIME& t2) @@ -222,6 +222,7 @@ private: ITEMTYPE m_type; // Indicates our type. See ITEMTYPE. CString m_name; // Display name mutable CString m_extension; // Cache of extension (it's used often) + mutable bool m_extension_cached = false; ULONGLONG m_size; // OwnSize, if IT_FILE or IT_FREESPACE, or IT_UNKNOWN; SubtreeTotal else. ULONGLONG m_files; // # Files in subtree ULONGLONG m_subdirs; // # Folder in subtree -- cgit v1.2.3