how can I speed up the code below which I use to check if a record is already in the database? Instruments tells me that the app spends about 10% of processing time in this method. For historical reasons (a.k.a stupidity) the method is a bit of a mess. In some cases I forgot to add the brackets around the message id. The vField is cached.
Public Sub Constructor(theMessageID as String, InternalMessageIDField as vField)
if theMessageID = "" or InternalMessageIDField = nil then
theResult = true
Return
end if
dim theCheckset as VArraySet
if left(theMessageID, 1) <> "<" and Right(theMessageID, 1) <> ">" then
theCheckset = InternalMessageIDField.FindValueAsArraySet(Left("<" + theMessageID + ">", 100))
if theCheckset = nil then
theResult = False
else
dim i as Integer = theCheckset.Count
if i = 0 then
theResult = False
else
theResult = true
end if
end if
if theResult = true then Return 'already found, if not try without brackets, AppleScript gives back the message id without brackets for Mail
theCheckset = nil
end if
theCheckset = InternalMessageIDField.FindValueAsArraySet(Left(theMessageID, 100))
if theCheckset = nil then
theResult = False
else
dim i as Integer = theCheckset.Count
if i = 0 then
theResult = False
else
theResult = true
end if
end if
if theResult = true then Return'already found,
'if not try with right bracket, found some cases where data has been entered with a right bracket only
theCheckset = nil
theCheckset = InternalMessageIDField.FindValueAsArraySet(Left(theMessageID + ">", 100))
if theCheckset = nil then
theResult = False
else
dim i as Integer = theCheckset.Count
if i = 0 then
theResult = False
else
theResult = true
end if
end if
End Sub
Oh, and after updating to Valentina 8.3.3 the code is a couple of seconds slower compared to 7.5.9.
Xojo 2018r1.1. Valentina 8.3.3, Mojave latest beta.
Regards
Beatrix Willius