android - Recursion making explorer slow -


this code check mp3 songs (using recursion)is making explorer slow please suggest me way make faster

public static boolean getmp3s1(file dir){             int h=0;              file[] listfile = dir.listfiles();              if(listfile!=null)              for( int i=0; i< listfile.length; i++)              {                  if(listfile[i].isdirectory()==true)                  getmp3s1(listfile[i]);                  else                  {                      if(listfile[i].getname().endswith(".mp3")==true||listfile[i].getname().endswith(".mp3")==true)                          h=1;             }            }          if(h==1){              h=0;              return true;         }          else              return false;          } 

try break loop after h=1; can speed little. bellow:

public static boolean getmp3s1(file dir){         int h=0;          file[] listfile = dir.listfiles();          if(listfile!=null)          for( int i=0; i< listfile.length; i++)          {              if(listfile[i].isdirectory()==true)              getmp3s1(listfile[i]);              else              {                  if(listfile[i].getname().endswith(".mp3")==true||listfile[i].getname().endswith(".mp3")==true)                     {                       h=1;                      break;                     }         }        }      if(h==1){          h=0;          return true;     }      else          return false;      } 

edit: see code logic seems can skip getmp3s1(listfile[i]); too.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -