From 5a7c950b899948d00e5e0aeab61fd4c517e45906 Mon Sep 17 00:00:00 2001 From: FPtje Date: Thu, 5 Nov 2015 19:56:42 +0100 Subject: Small optimisation in CItem::GetExtension() The profiler indicates that this function is the end of a hot path in the visualisation. @assarbad mentioned earlier that CStrings are slow, and with this commit we confirm that. --- windirstat/item.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/windirstat/item.cpp b/windirstat/item.cpp index e4f188c..89a128e 100644 --- a/windirstat/item.cpp +++ b/windirstat/item.cpp @@ -914,18 +914,22 @@ CString CItem::GetExtension() const CString ext; + CString name = GetName(); + switch (GetType()) { case IT_FILE: { - int i = GetName().ReverseFind(wds::chrDot); + int i = name.ReverseFind(wds::chrDot); if(i == -1) { ext = _T("."); } else { - ext = GetName().Mid(i); + // Faster than name.Mid(i); + LPCTSTR alpha = static_cast(name); + ext = &alpha[i]; } ext.MakeLower(); break; @@ -933,7 +937,7 @@ CString CItem::GetExtension() const case IT_FREESPACE: case IT_UNKNOWN: { - ext = GetName(); + ext = name; } break; -- cgit v1.2.3