Skip to content

Commit

Permalink
several performance tweaks
Browse files Browse the repository at this point in the history
* performance improvements
* resolved several compiler recommendations
  • Loading branch information
jochenwezel committed Aug 1, 2024
1 parent e5f3f7c commit e5660a4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
6 changes: 1 addition & 5 deletions CompuMaster.Data/CsvTables/CsvReadBaseOptions.vb
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
Imports System.Diagnostics.Eventing
Imports System.IO
Imports System.Text

Namespace CompuMaster.Data.CsvTables
Namespace CompuMaster.Data.CsvTables

Public MustInherit Class CsvReadBaseOptions

Expand Down
4 changes: 4 additions & 0 deletions CompuMaster.Data/DataQuery.AnyIDataProvider.vb
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,9 @@ Namespace CompuMaster.Data.DataQuery
Else
value = CType(MyReader(1), TValue)
End If
#Disable Warning CA1864 ' Methode "Dictionary.TryAdd(TKey, TValue)" bevorzugen -> RECOMMENDED FEATURE NOT SUPPORTED BY .NET 4
If Result.ContainsKey(key) Then
#Enable Warning CA1864 ' Methode "Dictionary.TryAdd(TKey, TValue)" bevorzugen
Result(key) = value
Else
Result.Add(key, value)
Expand Down Expand Up @@ -1039,7 +1041,9 @@ Namespace CompuMaster.Data.DataQuery
Else
value = New TValue?(CType(MyReader(1), TValue))
End If
#Disable Warning CA1864 ' Methode "Dictionary.TryAdd(TKey, TValue)" bevorzugen -> RECOMMENDED FEATURE NOT SUPPORTED BY .NET 4
If Result.ContainsKey(key) Then
#Enable Warning CA1864 ' Methode "Dictionary.TryAdd(TKey, TValue)" bevorzugen
Result(key) = value
Else
Result.Add(key, value)
Expand Down
4 changes: 2 additions & 2 deletions CompuMaster.Data/DataQuery.DataProvider.vb
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ Namespace CompuMaster.Data.DataQuery
Result = Strings.Replace(Me.ConnectionType.Name, "Connection", "")
Result = Strings.Replace(Result, "Connection".ToLowerInvariant, "")
Result = Strings.Replace(Result, "Connection".ToUpperInvariant, "")
If Result = "Sql" AndAlso (Me.AssemblyName.ToLowerInvariant = "system.data" OrElse Me.AssemblyName.ToLowerInvariant = "system.data.sqlclient") Then
If Result = "Sql" AndAlso (AssemblyName.Equals("system.data", StringComparison.OrdinalIgnoreCase) OrElse AssemblyName.Equals("system.data.sqlclient", StringComparison.OrdinalIgnoreCase)) Then
Result = "SqlClient"
ElseIf Result = "Odbc" AndAlso (Me.AssemblyName.ToLowerInvariant = "system.data" OrElse Me.AssemblyName.ToLowerInvariant = "system.data.odbc") Then
ElseIf Result = "Odbc" AndAlso (AssemblyName.Equals("system.data", StringComparison.OrdinalIgnoreCase) OrElse AssemblyName.Equals("system.data.odbc", StringComparison.OrdinalIgnoreCase)) Then
Result = "ODBC"
End If
Return Result
Expand Down
24 changes: 15 additions & 9 deletions CompuMaster.Data/DataTables.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ Namespace CompuMaster.Data
Dim columnExistsInDestination As Boolean = False
For MyDestTableCounter As Integer = 0 To destinationTable.Columns.Count - 1
If caseInsensitiveColumnNames Then
If destinationTable.Columns(MyDestTableCounter).ColumnName.ToUpperInvariant = sourceTable.Columns(MySourceTableCounter).ColumnName.ToUpperInvariant Then
If destinationTable.Columns(MyDestTableCounter).ColumnName.Equals(sourceTable.Columns(MySourceTableCounter).ColumnName, StringComparison.OrdinalIgnoreCase) Then
columnExistsInDestination = True
Exit For
End If
Expand Down Expand Up @@ -3335,6 +3335,18 @@ Namespace CompuMaster.Data
''' <returns></returns>
''' <remarks>Comparisons with DBNull.Value will return False or True, never DBNull.Value</remarks>
Public Shared Function CompareValuesOfUnknownType(ByVal value1 As Object, ByVal value2 As Object, ByVal compareStringsCaseInsensitive As Boolean) As Boolean
Return CompareValuesOfUnknownType(value1, value2, If(compareStringsCaseInsensitive, StringComparison.InvariantCultureIgnoreCase, StringComparison.Ordinal))
End Function

''' <summary>
''' Compare 2 values of unknown but same type
''' </summary>
''' <param name="value1">1st value</param>
''' <param name="value2">2nd value</param>
''' <param name="compareStringsCaseInsensitive">True to compare strings case insensitive, False for case sensitive</param>
''' <returns></returns>
''' <remarks>Comparisons with DBNull.Value will return False or True, never DBNull.Value</remarks>
Public Shared Function CompareValuesOfUnknownType(ByVal value1 As Object, ByVal value2 As Object, ByVal stringComparisonStyle As StringComparison) As Boolean
Dim TypeCheckValue As Object
If value1 Is Nothing Then
TypeCheckValue = value2
Expand All @@ -3354,14 +3366,8 @@ Namespace CompuMaster.Data
Return True
ElseIf TypeCheckValue.GetType Is GetType(String) Then
'Strings
If compareStringsCaseInsensitive = False Then
If CType(value1, String) <> CType(value2, String) Then
Return False
End If
Else
If StringNotNothingOrEmpty(CType(value1, String)).ToLower(Globalization.CultureInfo.InvariantCulture) <> StringNotNothingOrEmpty(CType(value2, String)).ToLower(Globalization.CultureInfo.InvariantCulture) Then
Return False
End If
If Not StringNotNothingOrEmpty(CType(value1, String)).Equals(StringNotNothingOrEmpty(CType(value2, String)), stringComparisonStyle) Then
Return False
End If
ElseIf TypeCheckValue.GetType Is GetType(System.Double) Then
'Doubles
Expand Down
16 changes: 4 additions & 12 deletions CompuMaster.Data/Manipulation.vb
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ Namespace CompuMaster.Data
''' <remarks></remarks>
Private Shared Function CreateTableCommandText(ByVal tableName As String, ByVal primaryColumnName As String, ByVal ddlLanguage As DdlLanguage) As String
Dim OpenBrackets, CloseBrackets As String
#Disable Warning CA2249 ' Erwägen Sie die Verwendung von "string.Contains" anstelle von "string.IndexOf"
If tableName.IndexOf("[", StringComparison.Ordinal) >= 0 AndAlso tableName.IndexOf("]", StringComparison.Ordinal) >= 0 Then
#Enable Warning CA2249 ' Erwägen Sie die Verwendung von "string.Contains" anstelle von "string.IndexOf"
If tableName.Contains("["c) AndAlso tableName.Contains("]"c) Then
'table name already in a well-formed syntax, e.g. "dbo.[Test - 123]"
OpenBrackets = Nothing
CloseBrackets = Nothing
Expand Down Expand Up @@ -318,9 +316,7 @@ Namespace CompuMaster.Data
<CodeAnalysis.SuppressMessage("Minor Code Smell", "S1643:Strings should not be concatenated using ""+"" or ""&"" in a loop", Justification:="<Ausstehend>")>
Public Shared Function AddMissingColumnsCommandText(ByVal sourceTable As DataTable, ByVal destinationTable As DataTable, remoteTableName As String, ByVal ddlLanguage As DdlLanguage) As String
Dim OpenBrackets, CloseBrackets As String
#Disable Warning CA2249 ' Erwägen Sie die Verwendung von "string.Contains" anstelle von "string.IndexOf"
If remoteTableName.IndexOf("[", StringComparison.Ordinal) >= 0 AndAlso remoteTableName.IndexOf("]", StringComparison.Ordinal) >= 0 Then
#Enable Warning CA2249 ' Erwägen Sie die Verwendung von "string.Contains" anstelle von "string.IndexOf"
If remoteTableName.Contains("["c) AndAlso remoteTableName.Contains("]"c) Then
'table name already in a well-formed syntax, e.g. "dbo.[Test - 123]"
OpenBrackets = Nothing
CloseBrackets = Nothing
Expand Down Expand Up @@ -489,9 +485,7 @@ Namespace CompuMaster.Data
''' <remarks></remarks>
Public Shared Function LoadTableDataForManipulationViaCode(ByVal dataConnection As IDbConnection, ByVal tableName As String, ByVal commandTimeout As Integer, isSafeTableName As Boolean) As CompuMaster.Data.DataManipulationResult
Dim OpenBrackets, CloseBrackets As String
#Disable Warning CA2249 ' Erwägen Sie die Verwendung von "string.Contains" anstelle von "string.IndexOf"
If tableName.IndexOf("[", StringComparison.Ordinal) >= 0 AndAlso tableName.IndexOf("]", StringComparison.Ordinal) >= 0 Then
#Enable Warning CA2249 ' Erwägen Sie die Verwendung von "string.Contains" anstelle von "string.IndexOf"
If tableName.Contains("["c) AndAlso tableName.Contains("]"c) Then
'table name already in a well-formed syntax, e.g. "dbo.[Test - 123]"
OpenBrackets = Nothing
CloseBrackets = Nothing
Expand Down Expand Up @@ -837,9 +831,7 @@ Namespace CompuMaster.Data
''' <remarks></remarks>
Private Shared Function LoadTableStructureWith1RowFromConnection(ByVal tableName As String, ByVal dataConnection As IDbConnection, ByVal ignoreExceptions As Boolean) As DataTable
Dim OpenBrackets, CloseBrackets As String
#Disable Warning CA2249 ' Erwägen Sie die Verwendung von "string.Contains" anstelle von "string.IndexOf"
If tableName.IndexOf("[", StringComparison.Ordinal) >= 0 AndAlso tableName.IndexOf("]", StringComparison.Ordinal) >= 0 Then
#Enable Warning CA2249 ' Erwägen Sie die Verwendung von "string.Contains" anstelle von "string.IndexOf"
If tableName.Contains("["c) AndAlso tableName.Contains("]"c) Then
'table name already in a well-formed syntax, e.g. "dbo.[Test - 123]"
OpenBrackets = Nothing
CloseBrackets = Nothing
Expand Down
15 changes: 15 additions & 0 deletions CompuMaster.Test.Tools.Data/DataTablesTest.vb
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,29 @@ Namespace CompuMaster.Test.Data
dt.Rows.Add(e)
Assert.AreEqual(0, CompuMaster.Data.DataTables.ColumnIndex(dt.Columns("hey")))
End Sub

<Test()> Public Sub CompareValuesOfUnknownType()
Dim dt As New DataTable
dt.Columns.Add("DummmyColumn")

Dim e As Integer = 23
Dim f As Integer = 24
Assert.IsTrue(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "D", False))
Assert.IsTrue(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "D", True))
Assert.IsFalse(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "E", False))
Assert.IsFalse(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "E", True))
Assert.IsFalse(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "d", False))
Assert.IsFalse(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("É", "é", False))
Assert.IsTrue(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("É", "é", True))
Assert.IsFalse(CompuMaster.Data.DataTables.CompareValuesOfUnknownType(e, f, False))
Assert.IsTrue(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "D", StringComparison.Ordinal))
Assert.IsTrue(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "D", StringComparison.OrdinalIgnoreCase))
Assert.IsFalse(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "E", StringComparison.Ordinal))
Assert.IsFalse(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "E", StringComparison.OrdinalIgnoreCase))
Assert.IsFalse(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "d", StringComparison.Ordinal))
Assert.IsTrue(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("D", "d", StringComparison.OrdinalIgnoreCase))
Assert.IsFalse(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("É", "é", StringComparison.Ordinal))
Assert.IsTrue(CompuMaster.Data.DataTables.CompareValuesOfUnknownType("É", "é", StringComparison.OrdinalIgnoreCase))
Assert.IsFalse(CompuMaster.Data.DataTables.CompareValuesOfUnknownType(e, f, False))
End Sub

Expand Down

0 comments on commit e5660a4

Please sign in to comment.