iOS Question Searching in a list of 8000 cities case insensitive

valentino s

Active Member
Licensed User
Longtime User
I'm writing some tests to learn the language.

The case: I want to search for cities from a text file with 8000 cities.

My questions are about style and speed, to discover if there are other better or faster options. In this moment I don't look for any sql solution, just to understand if some commands can be written better.

1) this is very fast. Great:
B4X:
  Dim cities As List = File.ReadList(File.DirAssets, "cities.txt")

2) insensitive search in debug mode is slow, in release mode it's fast (i limit however to the first 25 occurancies)
B4X:
stringa=stringa.ToLowerCase
Do While cnt < cntmax
     tmpstring=cities.Get(totcnt)
     tmpstring=tmpstring.ToLowerCase
     If (tmpstring.IndexOf(stringa)>-1 ) Then
       TableView1.AddSingleLine(cities.Get(totcnt))
         cnt=cnt+1
     End If
     totcnt=totcnt+1
     If totcnt = totcities Then
       Exit
     End If
   Loop

2a) is there any faster method in debug mode ?
2b) is regex faster than
B4X:
tmpstring=cities.Get(totcnt)
     tmpstring=tmpstring.ToLowerCase
     If (tmpstring.IndexOf(stringa)>-1 ) Then
?

3) there's a faster method to add items to tableview1, or there's a library/module better thant tableview ?
B4X:
TableView1.clear
do while
  TableView1.AddSingleLine(cities.Get(totcnt))
loop
TableView1.ReloadAll

Thanks in advance to all. The code is working, good for beginners as me to learn a very simple search in realtime in large list of items.
 

Attachments

  • mylist.zip
    42.5 KB · Views: 226

sorex

Expert
Licensed User
Longtime User
debug mode makes anything slow, you shouldn't compare that with how the app will act in the end. Use Release mode to test it at real speed and disable log write as that might slow down aswell.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
forgot to mention that regex is really powerfull but probably a lot slower than a simple compare. it's a bad example for regex usage actually.
 
Upvote 0

valentino s

Active Member
Licensed User
Longtime User
So: debug ok to test if app is working; release to test also speed (and if it works withoutwifi); clean project optimize debug mode.

Thank you all.
 
Upvote 0
Top