From: Lauri Kenttä Subject: [PATCH 2/3] comdlg32: Init clipboard format only once. Message-Id: <20160623112956.5621-2-lauri.kentta@gmail.com> Date: Thu, 23 Jun 2016 14:29:55 +0300 In-Reply-To: <20160623112956.5621-1-lauri.kentta@gmail.com> References: <20160623112956.5621-1-lauri.kentta@gmail.com> Related to bug 26803. When selecting 1000 files, RegisterClipboardFormat seems to take up a measurable amount of time. This can be avoided by initializing the clipboard format only once. In my opinion, this also makes the code more readable. This gives 5–10% speed-up for selecting 253 files with shift-click. Signed-off-by: Lauri Kenttä --- dlls/comdlg32/filedlg.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/dlls/comdlg32/filedlg.c b/dlls/comdlg32/filedlg.c index 8e64c1e..ffe1471 100644 --- a/dlls/comdlg32/filedlg.c +++ b/dlls/comdlg32/filedlg.c @@ -3740,15 +3740,6 @@ static int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, U return nFileCount; } -#define SETDefFormatEtc(fe,cf,med) \ -{ \ - (fe).cfFormat = cf;\ - (fe).dwAspect = DVASPECT_CONTENT; \ - (fe).ptd =NULL;\ - (fe).tymed = med;\ - (fe).lindex = -1;\ -}; - /* * DATAOBJECT Helper functions */ @@ -3772,6 +3763,25 @@ static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium) } /*********************************************************************** + * GetFormatEtc + * + * Get the FORMATETC used in the shell id list + */ +static FORMATETC* GetFormatEtc(void) +{ + static FORMATETC formatetc; + if (!formatetc.cfFormat) + { + formatetc.cfFormat = RegisterClipboardFormatA(CFSTR_SHELLIDLISTA); + formatetc.ptd = 0; + formatetc.dwAspect = DVASPECT_CONTENT; + formatetc.lindex = -1; + formatetc.tymed = TYMED_HGLOBAL; + } + return &formatetc; +} + +/*********************************************************************** * GetPidlFromDataObject * * Return pidl(s) by number from the cached DataObject @@ -3782,19 +3792,15 @@ LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex) { STGMEDIUM medium; - FORMATETC formatetc; LPITEMIDLIST pidl = NULL; TRACE("sv=%p index=%u\n", doSelected, nPidlIndex); if (!doSelected) return NULL; - - /* Set the FORMATETC structure*/ - SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLISTA), TYMED_HGLOBAL); /* Get the pidls from IDataObject */ - if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium))) + if(SUCCEEDED(IDataObject_GetData(doSelected, GetFormatEtc(), &medium))) { LPIDA cida = GlobalLock(medium.u.hGlobal); if(nPidlIndex <= cida->cidl) @@ -3816,17 +3822,13 @@ static UINT GetNumSelected( IDataObject *doSelected ) { UINT retVal = 0; STGMEDIUM medium; - FORMATETC formatetc; TRACE("sv=%p\n", doSelected); if (!doSelected) return 0; - /* Set the FORMATETC structure*/ - SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLISTA), TYMED_HGLOBAL); - /* Get the pidls from IDataObject */ - if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium))) + if(SUCCEEDED(IDataObject_GetData(doSelected, GetFormatEtc(), &medium))) { LPIDA cida = GlobalLock(medium.u.hGlobal); retVal = cida->cidl; -- 2.9.0