directory stream optimization

master
Daniel Kolesa 2015-09-08 00:49:50 +01:00
parent 80b6aa588b
commit d163028054
1 changed files with 14 additions and 7 deletions

View File

@ -244,9 +244,12 @@ struct DirectoryStream {
memcpy(buf, &path[0], path.size());
buf[path.size()] = '\0';
p_d = opendir(buf);
if (!pop_front() || !skip_dots()) {
close();
return false;
}
p_path = path;
pop_front();
return is_open();
return true;
}
bool is_open() const { return p_d != nullptr; }
@ -265,7 +268,7 @@ struct DirectoryStream {
struct dirent rdv;
struct dirent *rd;
while (pop_front(td, &rdv, &rd))
++ret;
ret += strcmp(rd->d_name, ".") && strcmp(rd->d_name, "..");
closedir(td);
return ret;
}
@ -300,10 +303,6 @@ private:
if (!d) return false;
if (readdir_r(d, dev, de))
return false;
while (*de && (!strcmp((*de)->d_name, ".") ||
!strcmp((*de)->d_name, "..")))
if (readdir_r(d, dev, de))
return false;
return !!*de;
}
@ -311,6 +310,14 @@ private:
return pop_front(p_d, &p_dev, &p_de);
}
bool skip_dots() {
while (p_de && (!strcmp(p_de->d_name, ".") ||
!strcmp(p_de->d_name, "..")))
if (readdir_r(p_d, &p_dev, &p_de))
return false;
return !!p_de;
}
FileInfo front() const {
if (!p_de)
return FileInfo();