Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize working with filters and extensions in FileDialog, decrease allocations #9599

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ namespace MS.Internal.AppModel
#region Structs

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct COMDLG_FILTERSPEC
internal readonly struct COMDLG_FILTERSPEC
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pszName;
public readonly string pszName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pszSpec;
public readonly string pszSpec;

public COMDLG_FILTERSPEC(string name, string spec)
{
pszName = name;
pszSpec = spec;
}
}

[StructLayout(LayoutKind.Sequential, Pack = 4)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,8 @@ namespace Microsoft.Win32
/// <summary>
/// An abstract base class for displaying common dialogs.
/// </summary>
/// <Remarks>
/// InheritanceDemand for UIPermission (UIPermissionWindow.AllWindows)
/// </Remarks>
public abstract class CommonDialog
{
//---------------------------------------------------
//
// Constructors
//
//---------------------------------------------------
//#region Constructors
//#endregion Constructors

//---------------------------------------------------
//
// Public Methods
Expand All @@ -60,10 +49,7 @@ public abstract class CommonDialog
/// performs initialization tasks for all common dialogs and then
/// calls RunDialog.
/// </summary>
/// <Remarks>
/// Callers must have UIPermission(UIPermissionWindow.AllWindows) to call this API.
/// </Remarks>
public virtual Nullable<bool> ShowDialog()
public virtual bool? ShowDialog()
{
CheckPermissionsToShowDialog();

Expand Down Expand Up @@ -126,10 +112,7 @@ public virtual Nullable<bool> ShowDialog()
/// <summary>
/// Runs a common dialog box, with the owner as the given Window
/// </summary>
/// <Remarks>
/// Callers must have UIPermission(UIPermissionWindow.AllWindows) to call this API.
/// </Remarks>
public Nullable<bool> ShowDialog(Window owner)
public bool? ShowDialog(Window owner)
{
CheckPermissionsToShowDialog();

Expand Down Expand Up @@ -200,14 +183,6 @@ public object Tag

#endregion Public Properties

//---------------------------------------------------
//
// Public Events
//
//---------------------------------------------------
//#region Public Events
//#endregion Public Events

//---------------------------------------------------
//
// Protected Methods
Expand Down Expand Up @@ -331,38 +306,6 @@ private void MoveToScreenCenter(HandleRef hWnd)

#endregion Internal Methods

//---------------------------------------------------
//
// Internal Properties
//
//---------------------------------------------------
//#region Internal Properties
//#endregion Internal Properties

//---------------------------------------------------
//
// Internal Events
//
//---------------------------------------------------
//#region Internal Events
//#endregion Internal Events

//---------------------------------------------------
//
// Private Methods
//
//---------------------------------------------------
//#region Private Methods
//#endregion Private Methods

//---------------------------------------------------
//
// Protected Properties
//
//---------------------------------------------------
//#region Protected Properties
//#endregion Protected Properties

//---------------------------------------------------
//
// Private Fields
Expand All @@ -373,7 +316,7 @@ private void MoveToScreenCenter(HandleRef hWnd)
// Private variable used to store data for the Tag property
private object _userData;

private Thread _thread = Thread.CurrentThread;
private readonly Thread _thread = Thread.CurrentThread;

/// <summary>
/// The owner hwnd passed into the dialog is stored as a private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,6 @@ private protected string[] CloneItemNames()

#endregion Internal Properties

//---------------------------------------------------
//
// Internal Events
//
//---------------------------------------------------
//#region Internal Events
//#endregion Internal Events

//---------------------------------------------------
//
// Private Methods
Expand Down Expand Up @@ -697,10 +689,10 @@ private protected sealed class VistaDialogEvents : IFileDialogEvents, IDisposabl
{
public delegate bool OnOkCallback(IFileDialog dialog);

private IFileDialog _dialog;
private readonly IFileDialog _dialog;

private OnOkCallback _okCallback;
uint _eventCookie;
private readonly OnOkCallback _okCallback;
private readonly uint _eventCookie;

public VistaDialogEvents(IFileDialog dialog, OnOkCallback okCallback)
{
Expand Down
Loading