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

Lauri Kenttä lauri.kentta at gmail.com
Wed Jul 6 05:27:42 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.

Try 3: Cache only CLIPFORMAT, not the whole FORMATETC.

Signed-off-by: Lauri Kenttä <lauri.kentta at gmail.com>
---
 dlls/comdlg32/filedlg.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/dlls/comdlg32/filedlg.c b/dlls/comdlg32/filedlg.c
index 282582b..276dfb0 100644
--- a/dlls/comdlg32/filedlg.c
+++ b/dlls/comdlg32/filedlg.c
@@ -3766,14 +3766,22 @@ 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;\
-};
+/***********************************************************************
+ *          SetDefFormatEtc
+ *
+ * Fill the FORMATETC used in the shell id list
+ */
+static void SetDefFormatEtc(FORMATETC* formatetc)
+{
+  static CLIPFORMAT cfFormat;
+  if (!cfFormat)
+    cfFormat = RegisterClipboardFormatA(CFSTR_SHELLIDLISTA);
+  formatetc->cfFormat = cfFormat;
+  formatetc->ptd = 0;
+  formatetc->dwAspect = DVASPECT_CONTENT;
+  formatetc->lindex = -1;
+  formatetc->tymed = TYMED_HGLOBAL;
+}
 
 /*
  * DATAOBJECT Helper functions
@@ -3817,7 +3825,7 @@ LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex)
         return NULL;
 	
     /* Set the FORMATETC structure*/
-    SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLISTA), TYMED_HGLOBAL);
+    SetDefFormatEtc(&formatetc);
 
     /* Get the pidls from IDataObject */
     if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
@@ -3849,7 +3857,7 @@ static UINT GetNumSelected( IDataObject *doSelected )
     if (!doSelected) return 0;
 
     /* Set the FORMATETC structure*/
-    SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLISTA), TYMED_HGLOBAL);
+    SetDefFormatEtc(&formatetc);
 
     /* Get the pidls from IDataObject */
     if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
-- 
2.9.0




More information about the wine-patches mailing list