forked from OctaForge/libostd
directory stream optimization
parent
80b6aa588b
commit
d163028054
|
@ -244,9 +244,12 @@ struct DirectoryStream {
|
||||||
memcpy(buf, &path[0], path.size());
|
memcpy(buf, &path[0], path.size());
|
||||||
buf[path.size()] = '\0';
|
buf[path.size()] = '\0';
|
||||||
p_d = opendir(buf);
|
p_d = opendir(buf);
|
||||||
|
if (!pop_front() || !skip_dots()) {
|
||||||
|
close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
p_path = path;
|
p_path = path;
|
||||||
pop_front();
|
return true;
|
||||||
return is_open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_open() const { return p_d != nullptr; }
|
bool is_open() const { return p_d != nullptr; }
|
||||||
|
@ -265,7 +268,7 @@ struct DirectoryStream {
|
||||||
struct dirent rdv;
|
struct dirent rdv;
|
||||||
struct dirent *rd;
|
struct dirent *rd;
|
||||||
while (pop_front(td, &rdv, &rd))
|
while (pop_front(td, &rdv, &rd))
|
||||||
++ret;
|
ret += strcmp(rd->d_name, ".") && strcmp(rd->d_name, "..");
|
||||||
closedir(td);
|
closedir(td);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -300,10 +303,6 @@ private:
|
||||||
if (!d) return false;
|
if (!d) return false;
|
||||||
if (readdir_r(d, dev, de))
|
if (readdir_r(d, dev, de))
|
||||||
return false;
|
return false;
|
||||||
while (*de && (!strcmp((*de)->d_name, ".") ||
|
|
||||||
!strcmp((*de)->d_name, "..")))
|
|
||||||
if (readdir_r(d, dev, de))
|
|
||||||
return false;
|
|
||||||
return !!*de;
|
return !!*de;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,6 +310,14 @@ private:
|
||||||
return pop_front(p_d, &p_dev, &p_de);
|
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 {
|
FileInfo front() const {
|
||||||
if (!p_de)
|
if (!p_de)
|
||||||
return FileInfo();
|
return FileInfo();
|
||||||
|
|
Loading…
Reference in New Issue