Accelerate path.listdir() (#18927)

* Accelerate path.listdir()

* restore old behavior, push filename only and not the full path to the list
This commit is contained in:
Christian Baars 2023-07-06 11:10:26 +02:00 committed by GitHub
parent c4f899a721
commit 4c0535687f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -140,27 +140,25 @@ extern "C" {
returnit = 1; returnit = 1;
case MPATH_ISDIR: case MPATH_ISDIR:
case MPATH_MODIFIED: { case MPATH_MODIFIED: {
// listdir and isdir both need to open the file. //isdir needs to open the file, listdir does not
// we use be_fopen because it pre-pends with '/'. // we use be_fopen because it pre-pends with '/'.
// without this TAS fails to find stuff at boot... // without this TAS fails to find stuff at boot...
File *dir = (File *)be_fopen(path, "r"); File *dir = (File *)be_fopen(path, "r");
if (dir) { if (dir) {
String fpath;
String fname;
switch (action){ switch (action){
case MPATH_LISTDIR: case MPATH_LISTDIR:
// fill out the list object dir->seekDir(0);
dir->rewindDirectory(); fpath = dir->getNextFileName();
while (1) { while (fpath.length() != 0) {
File entry = dir->openNextFile(); fname = fpath.substring(fpath.lastIndexOf("/") + 1);
if (!entry) { const char * fn = fname.c_str();
break; be_pushstring(vm, fn);
} be_data_push(vm, -2);
const char * fn = entry.name(); be_pop(vm, 1);
if (strcmp(fn, ".") && strcmp(fn, "..")) { fpath = dir->getNextFileName();
be_pushstring(vm, fn);
be_data_push(vm, -2);
be_pop(vm, 1);
}
} }
break; break;
case MPATH_ISDIR: case MPATH_ISDIR: