From 23630fff6d775ba9a583b6dc9d00ada5ff73337b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Sch=C3=A4ublin?= Date: Tue, 16 Nov 2021 22:43:09 +0100 Subject: [PATCH] feat(sqliteConnection): cache eventargs (#26291) --- src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs index bdf2463de74..840c9179eb1 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs @@ -40,6 +40,9 @@ public partial class SqliteConnection : DbConnection private bool _extensionsEnabled; private int? _defaultTimeout; + private static readonly StateChangeEventArgs _fromClosedToOpenEventArgs = new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open); + private static readonly StateChangeEventArgs _fromOpenToClosedEventArgs = new StateChangeEventArgs(ConnectionState.Open, ConnectionState.Closed); + static SqliteConnection() => BundleInitializer.Initialize(); @@ -287,7 +290,7 @@ public override void Open() throw; } - OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open)); + OnStateChange(_fromClosedToOpenEventArgs); } /// @@ -322,7 +325,7 @@ public override void Close() _innerConnection = null; _state = ConnectionState.Closed; - OnStateChange(new StateChangeEventArgs(ConnectionState.Open, ConnectionState.Closed)); + OnStateChange(_fromOpenToClosedEventArgs); } internal void Deactivate()