Is there any way to speed up retrieving a RowTag as Variant from a listbox? For instance, each row I have a series of special properties in a class I assign to RowTag:
But it’s super slow accessing this custom RowTag class of SidebarListboxData when converting it from a variant to a SidebarListboxData. At least, i think that’s where the bottleneck is.
Public Function RowInBounds(row As Integer) As Boolean
If row > me.RowCount-1 Then Return False
If row < 0 Then Return False
Return True
End Function
And so is this:
Public Function ActualRowIsEntireListHeaderKSW(Index As Integer) As Boolean
If me.RowCount > 0 and me.PrivateRowData(0).RowIsEntireListHeader and _
(index = me.ScrollPosition) Then
index = 0
End If
If Not me.RowInBounds(index) Then Return False
Return me.PrivateRowData(Index).RowIsEntireListHeader
End Function
Where privateRowData is this:
Private Function PrivateRowData(row_num As Integer) As SidebarListboxData
Var xData As SidebarListboxData = SidebarListboxData(Super.RowTagAt(row_num))
If xData = Nil Then
xData = New SidebarListboxData(False,Nil,kRowTypeNormal,Nil,False)
Super.RowTagAt(row_num) = xData
End If
Var c As New MyClass()
c.aaa = 111
c.bbb = 222
MyListBox.RowTagAt(row) = c // store
// Then reuse somewhere as
Var c As MyClass = MyListBox.RowTagAt(row)
MessageBox c.aaa.ToString + " " + c.bbb.ToString
The profiler will show you the total time, the number of calls and then the time per call.
The reason I’m asking is that what assigning a variant to a property of a particular type should take a minimal amount of time… like less than a millisecond.
But I notice that your routine creates a few instance if one hasn’t been assigned yet. Could it be that’s where the time actually is?
String.IndexOf() is 500x slower than Dictionary.HasKey… 3.3 seconds for the below code versus 0.006
Var dStart, dEnd As Double
Var i, iEnd As Integer
Var dDict As New Dictionary
Var sCheck() As String
For i = 1 to 10000
Var the_value As String = "Untitled Copy " + Str(i+1)
sCheck.Append the_value
dDict.Value(the_value) = True
Next
Var sFinal() As String
dStart = System.Microseconds
iEnd = sCheck.Count-1
For i = 0 to iEnd
If sCheck.IndexOf(sCheck(i)) = -1 Then Break
Next
dEnd = System.Microseconds
MsgBox Str((dEnd-dStart)/1000000) + " seconds"
dStart = System.Microseconds
iEnd = sCheck.Count-1
For i = 0 to iEnd
If Not dDict.HasKey(sCheck(i)) Then Break
Next
dEnd = System.Microseconds