Skip to content

Commit 59e9cc0

Browse files
authored
Optimize working with filters and extensions in FileDialog, decrease allocations (#9599)
* remove unnecessary split allocation, return extensions as ROS<string> * remove CAS remarks, finish up with the rest * use MemoryExtensions.Count instead of SpanSplitEnumerator<char> (edwardneal) * simplify Slice, use ContainsAny instead of IndexAny (halgab) * Post-merge issues
1 parent 1da1b88 commit 59e9cc0

File tree

7 files changed

+62
-319
lines changed

7 files changed

+62
-319
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ShellProvider.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ namespace MS.Internal.AppModel
2424
#region Structs
2525

2626
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
27-
internal struct COMDLG_FILTERSPEC
27+
internal readonly struct COMDLG_FILTERSPEC
2828
{
2929
[MarshalAs(UnmanagedType.LPWStr)]
30-
public string pszName;
30+
public readonly string pszName;
3131
[MarshalAs(UnmanagedType.LPWStr)]
32-
public string pszSpec;
32+
public readonly string pszSpec;
33+
34+
public COMDLG_FILTERSPEC(string name, string spec)
35+
{
36+
pszName = name;
37+
pszSpec = spec;
38+
}
3339
}
3440

3541
[StructLayout(LayoutKind.Sequential, Pack = 4)]

src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonDialog.cs

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,8 @@ namespace Microsoft.Win32
2828
/// <summary>
2929
/// An abstract base class for displaying common dialogs.
3030
/// </summary>
31-
/// <Remarks>
32-
/// InheritanceDemand for UIPermission (UIPermissionWindow.AllWindows)
33-
/// </Remarks>
3431
public abstract class CommonDialog
3532
{
36-
//---------------------------------------------------
37-
//
38-
// Constructors
39-
//
40-
//---------------------------------------------------
41-
//#region Constructors
42-
//#endregion Constructors
43-
4433
//---------------------------------------------------
4534
//
4635
// Public Methods
@@ -60,10 +49,7 @@ public abstract class CommonDialog
6049
/// performs initialization tasks for all common dialogs and then
6150
/// calls RunDialog.
6251
/// </summary>
63-
/// <Remarks>
64-
/// Callers must have UIPermission(UIPermissionWindow.AllWindows) to call this API.
65-
/// </Remarks>
66-
public virtual Nullable<bool> ShowDialog()
52+
public virtual bool? ShowDialog()
6753
{
6854
CheckPermissionsToShowDialog();
6955

@@ -126,10 +112,7 @@ public virtual Nullable<bool> ShowDialog()
126112
/// <summary>
127113
/// Runs a common dialog box, with the owner as the given Window
128114
/// </summary>
129-
/// <Remarks>
130-
/// Callers must have UIPermission(UIPermissionWindow.AllWindows) to call this API.
131-
/// </Remarks>
132-
public Nullable<bool> ShowDialog(Window owner)
115+
public bool? ShowDialog(Window owner)
133116
{
134117
CheckPermissionsToShowDialog();
135118

@@ -200,14 +183,6 @@ public object Tag
200183

201184
#endregion Public Properties
202185

203-
//---------------------------------------------------
204-
//
205-
// Public Events
206-
//
207-
//---------------------------------------------------
208-
//#region Public Events
209-
//#endregion Public Events
210-
211186
//---------------------------------------------------
212187
//
213188
// Protected Methods
@@ -331,38 +306,6 @@ private void MoveToScreenCenter(HandleRef hWnd)
331306

332307
#endregion Internal Methods
333308

334-
//---------------------------------------------------
335-
//
336-
// Internal Properties
337-
//
338-
//---------------------------------------------------
339-
//#region Internal Properties
340-
//#endregion Internal Properties
341-
342-
//---------------------------------------------------
343-
//
344-
// Internal Events
345-
//
346-
//---------------------------------------------------
347-
//#region Internal Events
348-
//#endregion Internal Events
349-
350-
//---------------------------------------------------
351-
//
352-
// Private Methods
353-
//
354-
//---------------------------------------------------
355-
//#region Private Methods
356-
//#endregion Private Methods
357-
358-
//---------------------------------------------------
359-
//
360-
// Protected Properties
361-
//
362-
//---------------------------------------------------
363-
//#region Protected Properties
364-
//#endregion Protected Properties
365-
366309
//---------------------------------------------------
367310
//
368311
// Private Fields
@@ -373,7 +316,7 @@ private void MoveToScreenCenter(HandleRef hWnd)
373316
// Private variable used to store data for the Tag property
374317
private object _userData;
375318

376-
private Thread _thread = Thread.CurrentThread;
319+
private readonly Thread _thread = Thread.CurrentThread;
377320

378321
/// <summary>
379322
/// The owner hwnd passed into the dialog is stored as a private

src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonItemDialog.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -500,14 +500,6 @@ private protected string[] CloneItemNames()
500500

501501
#endregion Internal Properties
502502

503-
//---------------------------------------------------
504-
//
505-
// Internal Events
506-
//
507-
//---------------------------------------------------
508-
//#region Internal Events
509-
//#endregion Internal Events
510-
511503
//---------------------------------------------------
512504
//
513505
// Private Methods
@@ -697,10 +689,10 @@ private protected sealed class VistaDialogEvents : IFileDialogEvents, IDisposabl
697689
{
698690
public delegate bool OnOkCallback(IFileDialog dialog);
699691

700-
private IFileDialog _dialog;
692+
private readonly IFileDialog _dialog;
701693

702-
private OnOkCallback _okCallback;
703-
uint _eventCookie;
694+
private readonly OnOkCallback _okCallback;
695+
private readonly uint _eventCookie;
704696

705697
public VistaDialogEvents(IFileDialog dialog, OnOkCallback okCallback)
706698
{

0 commit comments

Comments
 (0)