Message130286
| Author |
socketpair |
| Recipients |
Trundle, giampaolo.rodola, loewis, neologix, nvetoshkin, pitrou, socketpair |
| Date |
2011年03月07日.19:43:54 |
| SpamBayes Score |
5.191209e-06 |
| Marked as misclassified |
No |
| Message-id |
<1299527036.3.0.913790438649.issue11406@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
> Glibc's readdir() and readdir_r() already do caching
Yes, but glibc's readdir is the C analogue of python's generator. We do not need to create cache for cached values.
I think it's OK to make python's generator on top of readdir (instead of getdents).
Why not to create generator like this?
(pseudocode)
------------------
DIR *d;
struct dirent* entry, *e;
entry = malloc(offsetof(struct dirent, d_name) + pathconf(dirpath, _PC_NAME_MAX) + 1);
if (!e)
raise Exception();
if (!(d= opendir(dirname)))
{
free(e)
raise IOException();
}
for (;;)
{
if (readdir_r(d, entry, &e))
{
closedir(d);
free(entry);
raise IOException();
}
if (!e)
break;
yield e;
}
closedir(d);
free(entry);
------------------ |
|