Show
Ignore:
Timestamp:
12/23/07 14:12:23 (4 years ago)
Author:
rakshasa
Message:

* Refactoring utils::Directory.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/rtorrent/src/utils/directory.cc

    r938 r1022  
    4747namespace utils { 
    4848 
     49// Keep this? 
    4950bool 
    5051Directory::is_valid() const { 
     
    5859} 
    5960 
     61// Update should take various flags and sort functors. 
    6062bool 
    6163Directory::update(bool hideDot) { 
     
    7072  struct dirent* ent; 
    7173 
     74  // Err... let us use getdirentries here instead. 
    7275  while ((ent = readdir(d)) != NULL) { 
     76    // Don't construct it here, check the const char. 
    7377    std::string de(ent->d_name); 
    7478 
    75     if (!de.empty() && (!hideDot || de[0] != '.')) 
    76       Base::push_back(ent->d_name); 
     79    if (!de.empty() && (!hideDot || de[0] != '.')) { 
     80      iterator itr = base_type::insert(end(), value_type()); 
     81 
     82      itr->d_fileno = ent->d_fileno; 
     83      itr->d_reclen = ent->d_reclen; 
     84      itr->d_type   = ent->d_type; 
     85      itr->d_name   = de; 
     86    } 
    7787  } 
    7888 
    7989  closedir(d); 
    80   Base::sort(std::less<std::string>()); 
     90  std::sort(begin(), end()); 
    8191 
    8292  return true; 
    8393} 
    8494 
    85 Directory::Base 
     95std::vector<std::string> 
    8696Directory::make_list() { 
    87   Base l; 
     97  std::vector<std::string> l; 
     98  l.reserve(size()); 
    8899 
    89   for (Base::iterator itr = begin(); itr != end(); ++itr) 
    90     l.push_back(m_path + *itr); 
     100  for (iterator itr = begin(); itr != end(); ++itr) 
     101    l.push_back(m_path + itr->d_name); 
    91102 
    92103  return l;