From 1b6fc71a0b2d49d4fdb63055859b3eb66221e195 Mon Sep 17 00:00:00 2001 From: "deep@alchemy-d.com" Date: Wed, 14 Oct 2015 02:27:05 -0700 Subject: changed all ASSERT to WEAK_ASSERT --- windirstat/Controls/treemap.cpp | 142 ++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 71 deletions(-) (limited to 'windirstat') diff --git a/windirstat/Controls/treemap.cpp b/windirstat/Controls/treemap.cpp index 4df6958..5d1950e 100644 --- a/windirstat/Controls/treemap.cpp +++ b/windirstat/Controls/treemap.cpp @@ -47,8 +47,8 @@ double CColorSpace::GetColorBrightness(COLORREF color) COLORREF CColorSpace::MakeBrightColor(COLORREF color, double brightness) { - ASSERT(brightness >= 0.0); - ASSERT(brightness <= 1.0); + WEAK_ASSERT(brightness >= 0.0); + WEAK_ASSERT(brightness <= 1.0); double dred = (RGB_GET_RVALUE(color) & 0xFF) / 255.0; double dgreen = (RGB_GET_GVALUE(color) & 0xFF) / 255.0; @@ -80,7 +80,7 @@ bool CColorSpace::Is256Colors() void CColorSpace::NormalizeColor(int& red, int& green, int& blue) { - ASSERT(red + green + blue <= 3 * 255); + WEAK_ASSERT(red + green + blue <= 3 * 255); if(red > 255) { @@ -108,14 +108,14 @@ void CColorSpace::DistributeFirst(int& first, int& second, int& third) int h = second - 255; second = 255; third += h; - ASSERT(third <= 255); + WEAK_ASSERT(third <= 255); } else if(third > 255) { int h = third - 255; third = 255; second += h; - ASSERT(second <= 255); + WEAK_ASSERT(second <= 255); } } @@ -222,7 +222,7 @@ CTreemap::CTreemap(Callback *callback) void CTreemap::SetOptions(const Options *options) { - ASSERT(options != NULL); + WEAK_ASSERT(options != NULL); m_options = *options; // Derive normalized vector here for performance @@ -256,7 +256,7 @@ void CTreemap::RecurseCheckTree(Item *item) { if(item->TmiIsLeaf()) { - ASSERT(item->TmiGetChildrenCount() == 0); + WEAK_ASSERT(item->TmiGetChildrenCount() == 0); } else { @@ -268,7 +268,7 @@ void CTreemap::RecurseCheckTree(Item *item) sum += child->TmiGetSize(); RecurseCheckTree(child); } - ASSERT(sum == item->TmiGetSize()); + WEAK_ASSERT(sum == item->TmiGetSize()); } } #endif @@ -330,7 +330,7 @@ void CTreemap::DrawTreemap(CDC *pdc, CRect rc, Item *root, const Options *option { for(int y = rc.top; y < rc.bottom - m_options.grid; y++) { - ASSERT(FindItemByPoint(root, CPoint(x, y)) != NULL); + WEAK_ASSERT(FindItemByPoint(root, CPoint(x, y)) != NULL); } } #endif @@ -371,7 +371,7 @@ void CTreemap::DrawTreemapDoubleBuffered(CDC *pdc, const CRect& rc, Item *root, CTreemap::Item *CTreemap::FindItemByPoint(Item *item, CPoint point) { - ASSERT(item != NULL); + WEAK_ASSERT(item != NULL); const CRect& rc = item->TmiGetRectangle(); if(!rc.PtInRect(point)) @@ -388,7 +388,7 @@ CTreemap::Item *CTreemap::FindItemByPoint(Item *item, CPoint point) return NULL; } - ASSERT(rc.PtInRect(point)); + WEAK_ASSERT(rc.PtInRect(point)); Item *ret = NULL; @@ -404,14 +404,14 @@ CTreemap::Item *CTreemap::FindItemByPoint(Item *item, CPoint point) } else { - ASSERT(item->TmiGetSize() > 0); - ASSERT(item->TmiGetChildrenCount() > 0); + WEAK_ASSERT(item->TmiGetSize() > 0); + WEAK_ASSERT(item->TmiGetChildrenCount() > 0); for(int i = 0; i < item->TmiGetChildrenCount(); i++) { Item *child = item->TmiGetChild(i); - ASSERT(child->TmiGetSize() > 0); + WEAK_ASSERT(child->TmiGetSize() > 0); #ifdef _DEBUG CRect rcChild(child->TmiGetRectangle()); @@ -425,7 +425,7 @@ CTreemap::Item *CTreemap::FindItemByPoint(Item *item, CPoint point) if(child->TmiGetRectangle().PtInRect(point)) { ret = FindItemByPoint(child, point); - ASSERT(ret != NULL); + WEAK_ASSERT(ret != NULL); #ifdef STRONGDEBUG #ifdef _DEBUG for(i++; i < item->TmiGetChildrenCount(); i++) @@ -440,18 +440,18 @@ CTreemap::Item *CTreemap::FindItemByPoint(Item *item, CPoint point) rcChild = child->TmiGetRectangle(); if(rcChild.left == -1) { - ASSERT(rcChild.top == -1); - ASSERT(rcChild.right == -1); - ASSERT(rcChild.bottom == -1); + WEAK_ASSERT(rcChild.top == -1); + WEAK_ASSERT(rcChild.right == -1); + WEAK_ASSERT(rcChild.bottom == -1); break; } - ASSERT(rcChild.right >= rcChild.left); - ASSERT(rcChild.bottom >= rcChild.top); - ASSERT(rcChild.left >= rc.left); - ASSERT(rcChild.right <= rc.right); - ASSERT(rcChild.top >= rc.top); - ASSERT(rcChild.bottom <= rc.bottom); + WEAK_ASSERT(rcChild.right >= rcChild.left); + WEAK_ASSERT(rcChild.bottom >= rcChild.top); + WEAK_ASSERT(rcChild.left >= rc.left); + WEAK_ASSERT(rcChild.right <= rc.right); + WEAK_ASSERT(rcChild.top >= rc.top); + WEAK_ASSERT(rcChild.bottom <= rc.bottom); } #endif #endif @@ -461,7 +461,7 @@ CTreemap::Item *CTreemap::FindItemByPoint(Item *item, CPoint point) } } - ASSERT(ret != NULL); + WEAK_ASSERT(ret != NULL); if(ret == NULL) { @@ -506,8 +506,8 @@ void CTreemap::RecurseDrawGraph( DWORD flags ) { - ASSERT(rc.Width() >= 0); - ASSERT(rc.Height() >= 0); + WEAK_ASSERT(rc.Width() >= 0); + WEAK_ASSERT(rc.Height() >= 0); WEAK_ASSERT(item->TmiGetSize() > 0); @@ -546,8 +546,8 @@ void CTreemap::RecurseDrawGraph( } else { - ASSERT(item->TmiGetChildrenCount() > 0); - ASSERT(item->TmiGetSize() > 0); + WEAK_ASSERT(item->TmiGetChildrenCount() > 0); + WEAK_ASSERT(item->TmiGetSize() > 0); DrawChildren(pdc, item, surface, h, flags); } @@ -594,7 +594,7 @@ void CTreemap::DrawChildren( // void CTreemap::KDirStat_DrawChildren(CDC *pdc, Item *parent, const double *surface, double h, DWORD /*flags*/) { - ASSERT(parent->TmiGetChildrenCount() > 0); + WEAK_ASSERT(parent->TmiGetChildrenCount() > 0); const CRect& rc = parent->TmiGetRectangle(); @@ -608,8 +608,8 @@ void CTreemap::KDirStat_DrawChildren(CDC *pdc, Item *parent, const double *surfa const int width = horizontalRows ? rc.Width() : rc.Height(); const int height = horizontalRows ? rc.Height() : rc.Width(); - ASSERT(width >= 0); - ASSERT(height >= 0); + WEAK_ASSERT(width >= 0); + WEAK_ASSERT(height >= 0); int c = 0; double top = horizontalRows ? rc.top : rc.left; @@ -657,7 +657,7 @@ void CTreemap::KDirStat_DrawChildren(CDC *pdc, Item *parent, const double *surfa { CRect test; test.IntersectRect(parent->TmiGetRectangle(), rcChild); - ASSERT(test == rcChild); + WEAK_ASSERT(test == rcChild); } #endif @@ -678,10 +678,10 @@ void CTreemap::KDirStat_DrawChildren(CDC *pdc, Item *parent, const double *surfa left = fRight; } - // This asserts due to rounding error: ASSERT(left == (horizontalRows ? rc.right : rc.bottom)); + // This asserts due to rounding error: WEAK_ASSERT(left == (horizontalRows ? rc.right : rc.bottom)); top = fBottom; } - // This asserts due to rounding error: ASSERT(top == (horizontalRows ? rc.bottom : rc.right)); + // This asserts due to rounding error: WEAK_ASSERT(top == (horizontalRows ? rc.bottom : rc.right)); } @@ -694,8 +694,8 @@ bool CTreemap::KDirStat_ArrangeChildren( CArray& childrenPerRow ) { - ASSERT(!parent->TmiIsLeaf()); - ASSERT(parent->TmiGetChildrenCount() > 0); + WEAK_ASSERT(!parent->TmiIsLeaf()); + WEAK_ASSERT(parent->TmiGetChildrenCount() > 0); if(parent->TmiGetSize() == 0) { @@ -742,13 +742,13 @@ double CTreemap::KDirStat_CalcutateNextRow(Item *parent, const int nextChild, do { int i = 0; static const double _minProportion = 0.4; - ASSERT(_minProportion < 1); + WEAK_ASSERT(_minProportion < 1); - ASSERT(nextChild < parent->TmiGetChildrenCount()); - ASSERT(width >= 1.0); + WEAK_ASSERT(nextChild < parent->TmiGetChildrenCount()); + WEAK_ASSERT(width >= 1.0); const double mySize = (double)parent->TmiGetSize(); - ASSERT(mySize > 0); + WEAK_ASSERT(mySize > 0); ULONGLONG sizeUsed = 0; double rowHeight = 0; @@ -763,8 +763,8 @@ double CTreemap::KDirStat_CalcutateNextRow(Item *parent, const int nextChild, do sizeUsed += childSize; double virtualRowHeight = sizeUsed / mySize; - ASSERT(virtualRowHeight > 0); - ASSERT(virtualRowHeight <= 1); + WEAK_ASSERT(virtualRowHeight > 0); + WEAK_ASSERT(virtualRowHeight <= 1); // Rectangle(mySize) = width * 1.0 // Rectangle(childSize) = childWidth * virtualRowHeight @@ -774,7 +774,7 @@ double CTreemap::KDirStat_CalcutateNextRow(Item *parent, const int nextChild, do if(childWidth / virtualRowHeight < _minProportion) { - ASSERT(i > nextChild); // because width >= 1 and _minProportion < 1. + WEAK_ASSERT(i > nextChild); // because width >= 1 and _minProportion < 1. // For the first child we have: // childWidth / rowHeight // = childSize / mySize * width / rowHeight / rowHeight @@ -821,12 +821,12 @@ void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *su // Rest rectangle to fill CRect remaining(parent->TmiGetRectangle()); - ASSERT(remaining.Width() > 0); - ASSERT(remaining.Height() > 0); + WEAK_ASSERT(remaining.Width() > 0); + WEAK_ASSERT(remaining.Height() > 0); // Size of rest rectangle ULONGLONG remainingSize = parent->TmiGetSize(); - ASSERT(remainingSize > 0); + WEAK_ASSERT(remainingSize > 0); // Scale factor const double sizePerSquarePixel = (double)parent->TmiGetSize() / remaining.Width() / remaining.Height(); @@ -837,8 +837,8 @@ void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *su // At least one child left while(head < parent->TmiGetChildrenCount()) { - ASSERT(remaining.Width() > 0); - ASSERT(remaining.Height() > 0); + WEAK_ASSERT(remaining.Width() > 0); + WEAK_ASSERT(remaining.Height() > 0); // How we divide the remaining rectangle bool horizontal = (remaining.Width() >= remaining.Height()); @@ -848,7 +848,7 @@ void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *su // Square of height in size scale for ratio formula const double hh = (height * height) * sizePerSquarePixel; - ASSERT(hh > 0); + WEAK_ASSERT(hh > 0); // Row will be made up of child(rowBegin)...child(rowEnd - 1) int rowBegin = head; @@ -909,11 +909,11 @@ void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *su // As the size of parent is greater than zero, the size of // the first child must have been greater than zero, too. - ASSERT(sum > 0); + WEAK_ASSERT(sum > 0); // Width of row int width = (horizontal ? remaining.Width() : remaining.Height()); - ASSERT(width > 0); + WEAK_ASSERT(width > 0); if(sum < remainingSize) width = (int)((double)sum / remainingSize * width); @@ -963,13 +963,13 @@ void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *su rc.right = end; } - ASSERT(rc.left <= rc.right); - ASSERT(rc.top <= rc.bottom); + WEAK_ASSERT(rc.left <= rc.right); + WEAK_ASSERT(rc.top <= rc.bottom); - ASSERT(rc.left >= remaining.left); - ASSERT(rc.right <= remaining.right); - ASSERT(rc.top >= remaining.top); - ASSERT(rc.bottom <= remaining.bottom); + WEAK_ASSERT(rc.left >= remaining.left); + WEAK_ASSERT(rc.right <= remaining.right); + WEAK_ASSERT(rc.top >= remaining.top); + WEAK_ASSERT(rc.bottom <= remaining.bottom); RecurseDrawGraph(pdc, parent->TmiGetChild(i), rc, false, surface, h * m_options.scaleFactor, 0); @@ -991,10 +991,10 @@ void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *su remainingSize -= sum; - ASSERT(remaining.left <= remaining.right); - ASSERT(remaining.top <= remaining.bottom); + WEAK_ASSERT(remaining.left <= remaining.right); + WEAK_ASSERT(remaining.top <= remaining.bottom); - ASSERT(remainingSize >= 0); + WEAK_ASSERT(remainingSize >= 0); head += (rowEnd - rowBegin); @@ -1008,8 +1008,8 @@ void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *su break; } } - ASSERT(remainingSize == 0); - ASSERT(remaining.left == remaining.right || remaining.top == remaining.bottom); + WEAK_ASSERT(remainingSize == 0); + WEAK_ASSERT(remaining.left == remaining.right || remaining.top == remaining.bottom); } @@ -1018,20 +1018,20 @@ void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *su void CTreemap::Simple_DrawChildren(CDC *pdc, Item *parent, const double *surface, double h, DWORD flags) { #if 1 - ASSERT(0); // Not used in WinDirStat. + WEAK_ASSERT(0); // Not used in WinDirStat. pdc; parent; surface; h; flags; #else - ASSERT(parent->TmiGetChildrenCount() > 0); - ASSERT(parent->TmiGetSize() > 0); + WEAK_ASSERT(parent->TmiGetChildrenCount() > 0); + WEAK_ASSERT(parent->TmiGetSize() > 0); const CRect& rc = parent->TmiGetRectangle(); bool horizontal = (flags == 0); int width = horizontal ? rc.Width() : rc.Height(); - ASSERT(width >= 0); + WEAK_ASSERT(width >= 0); double fBegin = horizontal ? rc.left : rc.top; int veryEnd = horizontal ? rc.right : rc.bottom; @@ -1052,8 +1052,8 @@ void CTreemap::Simple_DrawChildren(CDC *pdc, Item *parent, const double *surface int begin = (int)fBegin; int end = (int)fEnd; - ASSERT(begin <= end); - ASSERT(end <= veryEnd); + WEAK_ASSERT(begin <= end); + WEAK_ASSERT(end <= veryEnd); CRect rcChild; if(horizontal) @@ -1200,7 +1200,7 @@ void CTreemap::DrawCushion(CDC *pdc, const CRect& rc, const double *surface, COL } pixel += Ia; - ASSERT(pixel <= 1.0); + WEAK_ASSERT(pixel <= 1.0); // Now, pixel is the brightness of the pixel, 0...1.0. @@ -1248,7 +1248,7 @@ void CTreemap::AddRidge(const CRect& rc, double *surface, double h) int width = rc.Width(); int height = rc.Height(); - ASSERT(width > 0 && height > 0); + WEAK_ASSERT(width > 0 && height > 0); double h4 = 4 * h; -- cgit v1.2.3 From 3c9c51ff93c18db779ad97f6faaf7977d031f804 Mon Sep 17 00:00:00 2001 From: "deep@alchemy-d.com" Date: Wed, 14 Oct 2015 02:28:49 -0700 Subject: problem with ambiguous overload call to abs .. fixed with fabs: int RoundDouble(double d) { return signum(d) * (int)(fabs(d) + 0.5); } see: http://stackoverflow.com/questions/1374037/ambiguous-overload-call-to-absdouble --- windirstat/Controls/treemap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'windirstat') diff --git a/windirstat/Controls/treemap.h b/windirstat/Controls/treemap.h index 046bf61..0d29382 100644 --- a/windirstat/Controls/treemap.h +++ b/windirstat/Controls/treemap.h @@ -142,7 +142,7 @@ public: void SetLightSourceYPercent(int n) { lightSourceY = n / 100.0; } void SetLightSourcePoint(CPoint pt) { SetLightSourceXPercent(pt.x); SetLightSourceYPercent(pt.y); } - int RoundDouble(double d) { return signum(d) * (int)(abs(d) + 0.5); } + int RoundDouble(double d) { return signum(d) * (int)(fabs(d) + 0.5); } }; public: -- cgit v1.2.3 From 95e5ef7266e0e25f88f499243f67332bbb048d21 Mon Sep 17 00:00:00 2001 From: "deep@alchemy-d.com" Date: Wed, 14 Oct 2015 02:31:16 -0700 Subject: Fails to descend/recurse into subdirectories: https://bitbucket.org/windirstat/windirstat/issues/133/fails-to-descend-recurse-into temporary workaround by preventing early exit by SetUndone.. // --- windirstat/item.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'windirstat') diff --git a/windirstat/item.cpp b/windirstat/item.cpp index 50452d9..ef15071 100644 --- a/windirstat/item.cpp +++ b/windirstat/item.cpp @@ -1135,6 +1135,11 @@ void CItem::DoSomeWork(DWORD ticks) } if(GetType() == IT_DRIVE || GetType() == IT_DIRECTORY || GetType() == IT_MYCOMPUTER) { + + // + ASSERT(IsReadJobDone()); if(IsDone()) { -- cgit v1.2.3 From 72d95e978d2fcd4b560b70e5697cbd0920a53640 Mon Sep 17 00:00:00 2001 From: FPtje Date: Thu, 5 Nov 2015 19:28:07 +0100 Subject: Render tree to bitmap instead of CDC This has quite a performance gain. The generation of the tree view went down from about four seconds to 700ms --- windirstat/Controls/treemap.cpp | 114 +++++++++++++++++++++++++++++++--------- windirstat/Controls/treemap.h | 23 ++++---- 2 files changed, 102 insertions(+), 35 deletions(-) (limited to 'windirstat') diff --git a/windirstat/Controls/treemap.cpp b/windirstat/Controls/treemap.cpp index 5d1950e..9183e06 100644 --- a/windirstat/Controls/treemap.cpp +++ b/windirstat/Controls/treemap.cpp @@ -29,6 +29,8 @@ #define new DEBUG_NEW #endif +#define BGR(b,g,r) ((COLORREF)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) + // I define the "brightness" of an rgb value as (r+b+g)/3/255. // The EqualizeColors() method creates a palette with colors // all having the same brightness of 0.6 @@ -314,6 +316,8 @@ void CTreemap::DrawTreemap(CDC *pdc, CRect rc, Item *root, const Options *option return; } + m_renderArea = rc; + if(root->TmiGetSize() > 0) { double surface[4]; @@ -322,7 +326,34 @@ void CTreemap::DrawTreemap(CDC *pdc, CRect rc, Item *root, const Options *option surface[i]= 0; } - RecurseDrawGraph(pdc, root, rc, true, surface, m_options.height, 0); + // Create a temporary CDC that represents only the tree map + CDC dcTreeView; + dcTreeView.CreateCompatibleDC(pdc); + + // This temporary CDC will be filled with this bitmap + CBitmap bmp; + + // That bitmap in turn will be created from this array + CArray *bitmap = new CArray; + bitmap->SetSize(rc.Width() * rc.Height()); + + // Recursively draw the tree graph + RecurseDrawGraph(bitmap, root, rc, true, surface, m_options.height, 0); + + // Fill the bitmap with the array + bmp.CreateBitmap(rc.Width(), rc.Height(), 1, 32, &(*bitmap)[0]); + + // Render bitmap to the temporary CDC + dcTreeView.SelectObject(&bmp); + + // And lastly, draw the temporary CDC to the real one + pdc->BitBlt(rc.TopLeft().x, rc.TopLeft().y, rc.Width(), rc.Height(), &dcTreeView, 0, 0, SRCCOPY); + + // Free memory + bmp.DeleteObject(); + dcTreeView.DeleteDC(); + delete bitmap; + #ifdef STRONGDEBUG // slow, but finds bugs! #ifdef _DEBUG @@ -486,7 +517,31 @@ void CTreemap::DrawColorPreview(CDC *pdc, const CRect& rc, COLORREF color, const AddRidge(rc, surface, m_options.height * m_options.scaleFactor); - RenderRectangle(pdc, rc, surface, color); + m_renderArea = rc; + + // Create a temporary CDC that represents only the tree map + CDC dcTreeView; + dcTreeView.CreateCompatibleDC(pdc); + + // This temporary CDC will be filled with this bitmap + CBitmap bmp; + + // That bitmap in turn will be created from this array + CArray *bitmap = new CArray; + bitmap->SetSize(rc.Width() * rc.Height()); + + // Recursively draw the tree graph + RenderRectangle(bitmap, CRect(0, 0, rc.Width(), rc.Height()), surface, color); + + // Fill the bitmap with the array + bmp.CreateBitmap(rc.Width(), rc.Height(), 1, 32, &(*bitmap)[0]); + + // Render bitmap to the temporary CDC + dcTreeView.SelectObject(&bmp); + + // And lastly, draw the temporary CDC to the real one + pdc->BitBlt(rc.TopLeft().x, rc.TopLeft().y, rc.Width(), rc.Height(), &dcTreeView, 0, 0, SRCCOPY); + if(m_options.grid) { CPen pen(PS_SOLID, 1, m_options.gridColor); @@ -494,10 +549,15 @@ void CTreemap::DrawColorPreview(CDC *pdc, const CRect& rc, COLORREF color, const CSelectStockObject sobrush(pdc, NULL_BRUSH); pdc->Rectangle(rc); } + + // Free memory + bmp.DeleteObject(); + dcTreeView.DeleteDC(); + delete bitmap; } void CTreemap::RecurseDrawGraph( - CDC *pdc, + CArray *bitmap, Item *item, const CRect& rc, bool asroot, @@ -542,14 +602,14 @@ void CTreemap::RecurseDrawGraph( if(item->TmiIsLeaf()) { - RenderLeaf(pdc, item, surface); + RenderLeaf(bitmap, item, surface); } else { WEAK_ASSERT(item->TmiGetChildrenCount() > 0); WEAK_ASSERT(item->TmiGetSize() > 0); - DrawChildren(pdc, item, surface, h, flags); + DrawChildren(bitmap, item, surface, h, flags); } } @@ -559,7 +619,7 @@ void CTreemap::RecurseDrawGraph( // pointers, factory methods and explicit destruction. It's not worth. void CTreemap::DrawChildren( - CDC *pdc, + CArray *bitmap, Item *parent, const double *surface, double h, @@ -570,19 +630,19 @@ void CTreemap::DrawChildren( { case KDirStatStyle: { - KDirStat_DrawChildren(pdc, parent, surface, h, flags); + KDirStat_DrawChildren(bitmap, parent, surface, h, flags); } break; case SequoiaViewStyle: { - SequoiaView_DrawChildren(pdc, parent, surface, h, flags); + SequoiaView_DrawChildren(bitmap, parent, surface, h, flags); } break; case SimpleStyle: { - Simple_DrawChildren(pdc, parent, surface, h, flags); + Simple_DrawChildren(bitmap, parent, surface, h, flags); } break; } @@ -592,7 +652,7 @@ void CTreemap::DrawChildren( // I learned this squarification style from the KDirStat executable. // It's the most complex one here but also the clearest, imho. // -void CTreemap::KDirStat_DrawChildren(CDC *pdc, Item *parent, const double *surface, double h, DWORD /*flags*/) +void CTreemap::KDirStat_DrawChildren(CArray *bitmap, Item *parent, const double *surface, double h, DWORD /*flags*/) { WEAK_ASSERT(parent->TmiGetChildrenCount() > 0); @@ -661,7 +721,7 @@ void CTreemap::KDirStat_DrawChildren(CDC *pdc, Item *parent, const double *surfa } #endif - RecurseDrawGraph(pdc, child, rcChild, false, surface, h * m_options.scaleFactor, 0); + RecurseDrawGraph(bitmap, child, rcChild, false, surface, h * m_options.scaleFactor, 0); if(lastChild) { @@ -816,7 +876,7 @@ double CTreemap::KDirStat_CalcutateNextRow(Item *parent, const int nextChild, do // The classical squarification method. // -void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *surface, double h, DWORD /*flags*/) +void CTreemap::SequoiaView_DrawChildren(CArray *bitmap, Item *parent, const double *surface, double h, DWORD /*flags*/) { // Rest rectangle to fill CRect remaining(parent->TmiGetRectangle()); @@ -971,7 +1031,7 @@ void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *su WEAK_ASSERT(rc.top >= remaining.top); WEAK_ASSERT(rc.bottom <= remaining.bottom); - RecurseDrawGraph(pdc, parent->TmiGetChild(i), rc, false, surface, h * m_options.scaleFactor, 0); + RecurseDrawGraph(bitmap, parent->TmiGetChild(i), rc, false, surface, h * m_options.scaleFactor, 0); if(lastChild) break; @@ -1015,12 +1075,12 @@ void CTreemap::SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *su // No squarification. Children are arranged alternately horizontally and vertically. // -void CTreemap::Simple_DrawChildren(CDC *pdc, Item *parent, const double *surface, double h, DWORD flags) +void CTreemap::Simple_DrawChildren(CArray *bitmap, Item *parent, const double *surface, double h, DWORD flags) { #if 1 WEAK_ASSERT(0); // Not used in WinDirStat. - pdc; parent; surface; h; flags; + bitmap; parent; surface; h; flags; #else WEAK_ASSERT(parent->TmiGetChildrenCount() > 0); @@ -1072,7 +1132,7 @@ void CTreemap::Simple_DrawChildren(CDC *pdc, Item *parent, const double *surface } RecurseDrawGraph( - pdc, + bitmap, parent->TmiGetChild(i), rcChild, false, @@ -1103,7 +1163,7 @@ bool CTreemap::IsCushionShading() && m_options.scaleFactor > 0.0; } -void CTreemap::RenderLeaf(CDC *pdc, Item *item, const double *surface) +void CTreemap::RenderLeaf(CArray *bitmap, Item *item, const double *surface) { CRect rc = item->TmiGetRectangle(); @@ -1117,10 +1177,10 @@ void CTreemap::RenderLeaf(CDC *pdc, Item *item, const double *surface) } } - RenderRectangle(pdc, rc, surface, item->TmiGetGraphColor()); + RenderRectangle(bitmap, rc, surface, item->TmiGetGraphColor()); } -void CTreemap::RenderRectangle(CDC *pdc, const CRect& rc, const double *surface, DWORD color) +void CTreemap::RenderRectangle(CArray *bitmap, const CRect& rc, const double *surface, DWORD color) { double brightness = m_options.brightness; @@ -1145,15 +1205,15 @@ void CTreemap::RenderRectangle(CDC *pdc, const CRect& rc, const double *surface, if(IsCushionShading()) { - DrawCushion(pdc, rc, surface, color, brightness); + DrawCushion(bitmap, rc, surface, color, brightness); } else { - DrawSolidRect(pdc, rc, color, brightness); + DrawSolidRect(bitmap, rc, color, brightness); } } -void CTreemap::DrawSolidRect(CDC *pdc, const CRect& rc, COLORREF col, double brightness) +void CTreemap::DrawSolidRect(CArray *bitmap, const CRect& rc, COLORREF col, double brightness) { int red = RGB_GET_RVALUE(col); int green = RGB_GET_GVALUE(col); @@ -1167,10 +1227,14 @@ void CTreemap::DrawSolidRect(CDC *pdc, const CRect& rc, COLORREF col, double bri CColorSpace::NormalizeColor(red, green, blue); - pdc->FillSolidRect(rc, RGB(red, green, blue)); + for (int iy = rc.top; iy < rc.bottom; iy++) + for (int ix = rc.left; ix < rc.right; ix++) + { + (*bitmap)[ix + iy * m_renderArea.Width()] = BGR(blue, green, red); + } } -void CTreemap::DrawCushion(CDC *pdc, const CRect& rc, const double *surface, COLORREF col, double brightness) +void CTreemap::DrawCushion(CArray *bitmap, const CRect& rc, const double *surface, COLORREF col, double brightness) { // Cushion parameters const double Ia = m_options.ambientLight; @@ -1221,7 +1285,7 @@ void CTreemap::DrawCushion(CDC *pdc, const CRect& rc, const double *surface, COL CColorSpace::NormalizeColor(red, green, blue); // ... and set! - pdc->SetPixel(ix, iy, RGB(red, green, blue)); + (*bitmap)[ix + iy * m_renderArea.Width()] = BGR(blue, green, red); } } diff --git a/windirstat/Controls/treemap.h b/windirstat/Controls/treemap.h index 0d29382..505289f 100644 --- a/windirstat/Controls/treemap.h +++ b/windirstat/Controls/treemap.h @@ -72,7 +72,7 @@ public: // If you prefer to use the getHead()/getNext() pattern rather // than using an array for the children, you will have to // rewrite CTreemap. - // + // class Item { public: @@ -187,7 +187,7 @@ public: protected: // The recursive drawing function void RecurseDrawGraph( - CDC *pdc, + CArray *bitmap, Item *item, const CRect& rc, bool asroot, @@ -198,7 +198,7 @@ protected: // This function switches to KDirStat-, SequoiaView- or Simple_DrawChildren void DrawChildren( - CDC *pdc, + CArray *bitmap, Item *parent, const double *surface, double h, @@ -206,15 +206,15 @@ protected: ); // KDirStat-like squarification - void KDirStat_DrawChildren(CDC *pdc, Item *parent, const double *surface, double h, DWORD flags); + void KDirStat_DrawChildren(CArray *bitmap, Item *parent, const double *surface, double h, DWORD flags); bool KDirStat_ArrangeChildren(Item *parent, CArray& childWidth, CArray& rows, CArray& childrenPerRow); double KDirStat_CalcutateNextRow(Item *parent, const int nextChild, double width, int& childrenUsed, CArray& childWidth); // Classical SequoiaView-like squarification - void SequoiaView_DrawChildren(CDC *pdc, Item *parent, const double *surface, double h, DWORD flags); + void SequoiaView_DrawChildren(CArray *bitmap, Item *parent, const double *surface, double h, DWORD flags); // No squarification (simple style, not used in WinDirStat) - void Simple_DrawChildren(CDC *pdc, Item *parent, const double *surface, double h, DWORD flags); + void Simple_DrawChildren(CArray *bitmap, Item *parent, const double *surface, double h, DWORD flags); // Sets brightness to a good value, if system has only 256 colors void SetBrightnessFor256(); @@ -223,16 +223,17 @@ protected: bool IsCushionShading(); // Leaves space for grid and then calls RenderRectangle() - void RenderLeaf(CDC *pdc, Item *item, const double *surface); + void RenderLeaf(CArray *bitmap, Item *item, const double *surface); // Either calls DrawCushion() or DrawSolidRect() - void RenderRectangle(CDC *pdc, const CRect& rc, const double *surface, DWORD color); + void RenderRectangle(CArray *bitmap, const CRect& rc, const double *surface, DWORD color); + // void RenderRectangle(CDC *pdc, const CRect& rc, const double *surface, DWORD color); // Draws the surface using SetPixel() - void DrawCushion(CDC *pdc, const CRect& rc, const double *surface, COLORREF col, double brightness); + void DrawCushion(CArray *bitmap, const CRect& rc, const double *surface, COLORREF col, double brightness); // Draws the surface using FillSolidRect() - void DrawSolidRect(CDC *pdc, const CRect& rc, COLORREF col, double brightness); + void DrawSolidRect(CArray *bitmap, const CRect& rc, COLORREF col, double brightness); // Adds a new ridge to surface static void AddRidge(const CRect& rc, double *surface, double h); @@ -242,6 +243,8 @@ protected: static const COLORREF _defaultCushionColors[]; // Standard palette for WinDirStat static const COLORREF _defaultCushionColors256[]; // Palette for 256-colors mode + CRect m_renderArea; + Options m_options; // Current options double m_Lx; // Derived parameters double m_Ly; -- cgit v1.2.3 From b97a4a154b3483a6715866e6ef586b28e1e0dda3 Mon Sep 17 00:00:00 2001 From: FPtje Date: Thu, 5 Nov 2015 19:31:08 +0100 Subject: Cache the file extension of files Small optimisation, prevents it from having to be calculated often. --- windirstat/item.cpp | 5 +++++ windirstat/item.h | 1 + 2 files changed, 6 insertions(+) (limited to 'windirstat') diff --git a/windirstat/item.cpp b/windirstat/item.cpp index ef15071..f71f5be 100644 --- a/windirstat/item.cpp +++ b/windirstat/item.cpp @@ -909,6 +909,9 @@ CString CItem::GetName() const CString CItem::GetExtension() const { + if (m_extension != "") + return m_extension; + CString ext; switch (GetType()) @@ -938,6 +941,8 @@ CString CItem::GetExtension() const ASSERT(0); } + m_extension = ext; + return ext; } diff --git a/windirstat/item.h b/windirstat/item.h index e6e748f..e9778e9 100644 --- a/windirstat/item.h +++ b/windirstat/item.h @@ -221,6 +221,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) 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 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 From 160a305b3a32c943d5eb63a387221c678b2c6f8e Mon Sep 17 00:00:00 2001 From: FPtje Date: Thu, 5 Nov 2015 19:49:14 +0100 Subject: Fixed WinDirStat's completely broken visualisation The bug is caused by the fact that an unsigned long long minus an unsigned long long is ALWAYS positive. The quicksort function algorithm used `signum` to compare unsigned long longs. With signum always returning either 1 or 0 (because always positive), the sorting was pretty much useless. With an arbitrary sorting order in multiple locations of the program, nothing was grouped correctly and the wrong file extensions got a colour assigned. The bug was introduced in revision 151. --- windirstat/Controls/typeview.cpp | 4 ++-- windirstat/Dialogs/SelectDrivesDlg.cpp | 4 ++-- windirstat/dirstatdoc.cpp | 2 +- windirstat/item.cpp | 12 ++++++------ windirstat/stdafx.h | 3 +++ 5 files changed, 14 insertions(+), 11 deletions(-) (limited to 'windirstat') diff --git a/windirstat/Controls/typeview.cpp b/windirstat/Controls/typeview.cpp index 756bd7e..9b09372 100644 --- a/windirstat/Controls/typeview.cpp +++ b/windirstat/Controls/typeview.cpp @@ -182,13 +182,13 @@ int CExtensionListControl::CListItem::Compare(const CSortingListItem *baseOther, case COL_COLOR: case COL_BYTES: { - r = signum(m_record.bytes - other->m_record.bytes); + r = usignum(m_record.bytes, other->m_record.bytes); } break; case COL_FILES: { - r = signum(m_record.files - other->m_record.files); + r = usignum(m_record.files, other->m_record.files); } break; diff --git a/windirstat/Dialogs/SelectDrivesDlg.cpp b/windirstat/Dialogs/SelectDrivesDlg.cpp index 7232211..7b23e21 100644 --- a/windirstat/Dialogs/SelectDrivesDlg.cpp +++ b/windirstat/Dialogs/SelectDrivesDlg.cpp @@ -166,12 +166,12 @@ int CDriveItem::Compare(const CSortingListItem *baseOther, int subitem) const break; case COL_TOTAL: { - r = signum(m_totalBytes - other->m_totalBytes); + r = usignum(m_totalBytes, other->m_totalBytes); } break; case COL_FREE: { - r = signum(m_freeBytes - other->m_freeBytes); + r = usignum(m_freeBytes, other->m_freeBytes); } break; case COL_GRAPH: diff --git a/windirstat/dirstatdoc.cpp b/windirstat/dirstatdoc.cpp index 01277ec..61e66c2 100644 --- a/windirstat/dirstatdoc.cpp +++ b/windirstat/dirstatdoc.cpp @@ -808,7 +808,7 @@ int __cdecl CDirstatDoc::_compareExtensions(const void *item1, const void *item2 SExtensionRecord r2; VERIFY(_pqsortExtensionData->Lookup(*ext1, r1)); VERIFY(_pqsortExtensionData->Lookup(*ext2, r2)); - return signum(r2.bytes - r1.bytes); + return usignum(r2.bytes, r1.bytes); } void CDirstatDoc::SetWorkingItemAncestor(CItem *item) diff --git a/windirstat/item.cpp b/windirstat/item.cpp index 0219fe7..e4f188c 100644 --- a/windirstat/item.cpp +++ b/windirstat/item.cpp @@ -277,7 +277,7 @@ int CItem::CompareSibling(const CTreeListItem *tlib, int subitem) const case COL_SUBTREEPERCENTAGE: if(MustShowReadJobs()) { - r = signum(m_readJobs - other->m_readJobs); + r = usignum(m_readJobs, other->m_readJobs); } else { @@ -293,25 +293,25 @@ int CItem::CompareSibling(const CTreeListItem *tlib, int subitem) const case COL_SUBTREETOTAL: { - r = signum(GetSize() - other->GetSize()); + r = usignum(GetSize(), other->GetSize()); } break; case COL_ITEMS: { - r = signum(GetItemsCount() - other->GetItemsCount()); + r = usignum(GetItemsCount(), other->GetItemsCount()); } break; case COL_FILES: { - r = signum(GetFilesCount() - other->GetFilesCount()); + r = usignum(GetFilesCount(), other->GetFilesCount()); } break; case COL_SUBDIRS: { - r = signum(GetSubdirsCount() - other->GetSubdirsCount()); + r = usignum(GetSubdirsCount(), other->GetSubdirsCount()); } break; @@ -1650,7 +1650,7 @@ int __cdecl CItem::_compareBySize(const void *p1, const void *p2) // TODO: Use 2nd sort column (as set in our TreeListView?) - return signum(size2 - size1); // biggest first + return usignum(size2, size1); // biggest first } ULONGLONG CItem::GetProgressRangeMyComputer() const diff --git a/windirstat/stdafx.h b/windirstat/stdafx.h index 1514704..8c34010 100644 --- a/windirstat/stdafx.h +++ b/windirstat/stdafx.h @@ -78,6 +78,9 @@ template int signum(T x) { return (x) < 0 ? -1 : (x) == 0 ? 0 : 1; } +/// signum function for unsigned numbers. +template int usignum(T x, T y) { return (x) < (y) ? -1 : (x) == (y) ? 0 : 1; } + #define WEAK_ASSERT /##/ ASSERT #endif // __WDS_STDAFX_H__ -- cgit v1.2.3 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(-) (limited to 'windirstat') 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 From 67c98b6bf49e623a6ceaa6f13c0c2dafca070cb1 Mon Sep 17 00:00:00 2001 From: FPtje Date: Thu, 5 Nov 2015 19:59:09 +0100 Subject: Cache the enum of GetType() GetType() is called very often. The cast and masking is unnecessary most of the time. --- windirstat/item.cpp | 5 +++-- windirstat/item.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'windirstat') diff --git a/windirstat/item.cpp b/windirstat/item.cpp index 89a128e..d788cf8 100644 --- a/windirstat/item.cpp +++ b/windirstat/item.cpp @@ -55,6 +55,7 @@ CItem::CItem(ITEMTYPE type, LPCTSTR name, bool dontFollow) , m_readJobs(0) , m_attributes(0) { + m_etype = (ITEMTYPE)(m_type & ~ITF_FLAGS); // returned by GetType if(GetType() == IT_FILE || dontFollow || GetType() == IT_FREESPACE || GetType() == IT_UNKNOWN || GetType() == IT_MYCOMPUTER) { SetReadJobDone(); @@ -829,7 +830,7 @@ double CItem::GetFraction() const ITEMTYPE CItem::GetType() const { - return (ITEMTYPE)(m_type & ~ITF_FLAGS); + return m_etype; } bool CItem::IsRootItem() const @@ -923,7 +924,7 @@ CString CItem::GetExtension() const int i = name.ReverseFind(wds::chrDot); if(i == -1) { - ext = _T("."); + ext = L"."; } else { diff --git a/windirstat/item.h b/windirstat/item.h index 4bcd4e3..55f2bba 100644 --- a/windirstat/item.h +++ b/windirstat/item.h @@ -220,6 +220,7 @@ private: void DrivePacman(); ITEMTYPE m_type; // Indicates our type. See ITEMTYPE. + ITEMTYPE m_etype; CString m_name; // Display name mutable CString m_extension; // Cache of extension (it's used often) mutable bool m_extension_cached = false; -- cgit v1.2.3 From c91d9bb5f4be3bdbc8dd112fd8f68ff4b99d70e4 Mon Sep 17 00:00:00 2001 From: FPtje Date: Thu, 5 Nov 2015 20:02:54 +0100 Subject: Initialise the hash map containing extension data with 2048 entries 2048 is a decent estimation for the amount of unique extensions one can have on one's hard drive. On a hard drive scan, this gave a decent performance boost. On my machine I got a difference from 280ms to 220ms on average. --- windirstat/dirstatdoc.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'windirstat') diff --git a/windirstat/dirstatdoc.cpp b/windirstat/dirstatdoc.cpp index 61e66c2..dee3ede 100644 --- a/windirstat/dirstatdoc.cpp +++ b/windirstat/dirstatdoc.cpp @@ -749,6 +749,8 @@ void CDirstatDoc::RebuildExtensionData() CWaitCursor wc; m_extensionData.RemoveAll(); + // 2048 is a rough estimate for amount of different extensions + m_extensionData.InitHashTable(2048); m_rootItem->RecurseCollectExtensionData(&m_extensionData); CStringArray sortedExtensions; -- cgit v1.2.3