[PATCH v2 1/3] comdlg32: Init clipboard format only once in filedlg.

Lauri Kenttä lauri.kentta at gmail.com
Sat Jun 25 05:49:11 CDT 2016


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ä <lauri.kentta at gmail.com>
---
 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 282582b..fa12618 100644
--- a/dlls/comdlg32/filedlg.c
+++ b/dlls/comdlg32/filedlg.c
@@ -3766,15 +3766,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
  */
@@ -3798,6 +3789,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
@@ -3808,19 +3818,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)
@@ -3842,17 +3848,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




More information about the wine-patches mailing list