mirror of
https://github.com/reactos/reactos.git
synced 2025-01-05 22:12:46 +00:00
[BROWSEUI]
- CProgressDialog: Allocate big enough buffers needed for the text messages during initialization and don't reallocate them at all. Should stop thrashing the heap while copying a large number of files. CORE-9252 svn path=/trunk/; revision=66992
This commit is contained in:
parent
2f48b949ad
commit
a2901cea9f
2 changed files with 25 additions and 50 deletions
|
@ -40,51 +40,47 @@
|
||||||
|
|
||||||
#define ID_3SECONDS 101
|
#define ID_3SECONDS 101
|
||||||
|
|
||||||
|
#define BUFFER_SIZE 256
|
||||||
|
|
||||||
CProgressDialog::CProgressDialog()
|
CProgressDialog::CProgressDialog()
|
||||||
{
|
{
|
||||||
ULONG cb = 32 *sizeof(WCHAR);
|
this->lines[0] = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, BUFFER_SIZE);
|
||||||
this->lines[0] = (LPWSTR) heap_alloc_zero(cb);
|
this->lines[1] = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, BUFFER_SIZE);
|
||||||
this->lines[1] = (LPWSTR) heap_alloc_zero(cb);
|
this->lines[2] = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, BUFFER_SIZE);
|
||||||
this->lines[2] = (LPWSTR) heap_alloc_zero(cb);
|
this->cancelMsg = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, BUFFER_SIZE);
|
||||||
this->cancelMsg = (LPWSTR) heap_alloc_zero(cb);
|
this->title = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, BUFFER_SIZE);
|
||||||
this->title = (LPWSTR) heap_alloc_zero(cb);
|
|
||||||
|
this->lines[0][0] = this->lines[1][0] = this->lines[2][0] = 0;
|
||||||
|
this->cancelMsg[0] = this->title[0];
|
||||||
|
|
||||||
this->clockHand = -1;
|
this->clockHand = -1;
|
||||||
this->progressClock[29].ullMark = 0ull;
|
this->progressClock[29].ullMark = 0ull;
|
||||||
this->dwStartTime = GetTickCount();
|
this->dwStartTime = GetTickCount();
|
||||||
|
|
||||||
InitializeCriticalSection(&this->cs);
|
InitializeCriticalSection(&this->cs);
|
||||||
this->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ProgressDialog.cs");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CProgressDialog::~CProgressDialog()
|
CProgressDialog::~CProgressDialog()
|
||||||
{
|
{
|
||||||
if (this->hwnd)
|
if (this->hwnd)
|
||||||
this->end_dialog();
|
this->end_dialog();
|
||||||
heap_free(this->lines[0]);
|
HeapFree(GetProcessHeap(), 0, this->lines[0]);
|
||||||
heap_free(this->lines[1]);
|
HeapFree(GetProcessHeap(), 0, this->lines[1]);
|
||||||
heap_free(this->lines[2]);
|
HeapFree(GetProcessHeap(), 0, this->lines[2]);
|
||||||
heap_free(this->cancelMsg);
|
HeapFree(GetProcessHeap(), 0, this->cancelMsg);
|
||||||
heap_free(this->title);
|
HeapFree(GetProcessHeap(), 0, this->title);
|
||||||
this->cs.DebugInfo->Spare[0] = 0;
|
|
||||||
DeleteCriticalSection(&this->cs);
|
DeleteCriticalSection(&this->cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_buffer(LPWSTR *buffer, LPCWSTR string)
|
static void set_buffer(LPWSTR *buffer, LPCWSTR string)
|
||||||
{
|
{
|
||||||
static const WCHAR empty_string[] = {0};
|
if (!string)
|
||||||
ULONG len;
|
{
|
||||||
|
buffer[0] = 0;
|
||||||
if (string == NULL)
|
return;
|
||||||
string = empty_string;
|
}
|
||||||
len = (wcslen(string) + 1)*sizeof(WCHAR);
|
|
||||||
|
|
||||||
LPWSTR tmp = (LPWSTR) heap_realloc(*buffer, len);
|
|
||||||
if (tmp)
|
|
||||||
*buffer = tmp;
|
|
||||||
else
|
|
||||||
len = wcslen(*buffer) + 1;
|
|
||||||
|
|
||||||
|
ULONG len = max((wcslen(string) + 1)*sizeof(WCHAR), BUFFER_SIZE);
|
||||||
StringCchCopyW(*buffer, len, string);
|
StringCchCopyW(*buffer, len, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,15 +91,13 @@ struct create_params
|
||||||
HWND hwndParent;
|
HWND hwndParent;
|
||||||
};
|
};
|
||||||
|
|
||||||
static LPWSTR load_string(HINSTANCE hInstance, UINT uiResourceId)
|
static void load_string(LPWSTR *buffer, HINSTANCE hInstance, UINT uiResourceId)
|
||||||
{
|
{
|
||||||
WCHAR string[256];
|
WCHAR string[256];
|
||||||
LPWSTR ret;
|
|
||||||
|
|
||||||
LoadStringW(hInstance, uiResourceId, string, sizeof(string)/sizeof(string[0]));
|
LoadStringW(hInstance, uiResourceId, string, sizeof(string)/sizeof(string[0]));
|
||||||
ret = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, (wcslen(string) + 1) * sizeof(WCHAR));
|
|
||||||
StrCpyW(ret, string);
|
set_buffer(buffer, string);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProgressDialog::set_progress_marquee()
|
void CProgressDialog::set_progress_marquee()
|
||||||
|
@ -210,8 +204,7 @@ static INT_PTR CALLBACK dialog_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l
|
||||||
This->isCancelled = TRUE;
|
This->isCancelled = TRUE;
|
||||||
|
|
||||||
if (!This->cancelMsg[0]) {
|
if (!This->cancelMsg[0]) {
|
||||||
heap_free(This->cancelMsg);
|
load_string(&This->cancelMsg, _AtlBaseModule.GetResourceInstance(), IDS_CANCELLING);
|
||||||
This->cancelMsg = load_string(_AtlBaseModule.GetResourceInstance(), IDS_CANCELLING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
This->set_progress_marquee();
|
This->set_progress_marquee();
|
||||||
|
@ -238,7 +231,6 @@ static INT_PTR CALLBACK dialog_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l
|
||||||
// A guess for time remaining based on the start time and current position
|
// A guess for time remaining based on the start time and current position
|
||||||
DWORD timeLeftI = (DWORD) runDiff * ((double) sizeLeft) / ((double) This->progressClock[This->clockHand].ullMark);
|
DWORD timeLeftI = (DWORD) runDiff * ((double) sizeLeft) / ((double) This->progressClock[This->clockHand].ullMark);
|
||||||
|
|
||||||
heap_realloc(&This->lines[2], 128);
|
|
||||||
StrFromTimeIntervalW(This->lines[2], 128, timeLeftD * 0.3 + timeLeftI * 0.7 , 2);
|
StrFromTimeIntervalW(This->lines[2], 128, timeLeftD * 0.3 + timeLeftI * 0.7 , 2);
|
||||||
This->update_dialog( UPDATE_LINE1 << 2 );
|
This->update_dialog( UPDATE_LINE1 << 2 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,21 +81,4 @@ BEGIN_COM_MAP(CProgressDialog)
|
||||||
END_COM_MAP()
|
END_COM_MAP()
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void *heap_alloc(size_t size)
|
|
||||||
{
|
|
||||||
return HeapAlloc(GetProcessHeap(), 0, size);
|
|
||||||
}
|
|
||||||
static inline void *heap_alloc_zero(size_t size)
|
|
||||||
{
|
|
||||||
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
|
||||||
}
|
|
||||||
static inline void *heap_realloc(void *mem, size_t size)
|
|
||||||
{
|
|
||||||
return mem ? HeapReAlloc(GetProcessHeap(), 0, mem, size) : heap_alloc(size);
|
|
||||||
}
|
|
||||||
static inline BOOL heap_free(void *mem)
|
|
||||||
{
|
|
||||||
return HeapFree(GetProcessHeap(), 0, mem);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* _PROGRESSDIALOG_H_ */
|
#endif /* _PROGRESSDIALOG_H_ */
|
||||||
|
|
Loading…
Reference in a new issue