Mercurial > hg > octave-lyh
changeset 8326:545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 17 Nov 2008 20:04:23 -0500 |
parents | b93ac0586e4b |
children | 4a7a943581d0 |
files | liboctave/ChangeLog liboctave/dir-ops.cc |
diffstat | 2 files changed, 13 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2008-11-17 John W. Eaton <jwe@octave.org> + + * dir-ops.cc (dir_entry::read): Use std::list<std::string> to + cache names before converting to string_vector. + 2008-11-14 David Bateman <dbateman@free.fr> * Array2.h (Array2<T> Array2<T>::index): Correct use of
--- a/liboctave/dir-ops.cc +++ b/liboctave/dir-ops.cc @@ -28,6 +28,9 @@ #include <cstdlib> #include <cstring> +#include <list> +#include <string> + #include "sysdir.h" #include "dir-ops.h" @@ -69,40 +72,26 @@ string_vector dir_entry::read (void) { - static octave_idx_type grow_size = 100; - - octave_idx_type len = 0; - - string_vector dirlist; + string_vector retval; if (ok ()) { - int count = 0; + std::list<std::string> dirlist; struct dirent *dir_ent; while ((dir_ent = readdir (static_cast<DIR *> (dir)))) { if (dir_ent) - { - if (count >= len) - { - len += grow_size; - dirlist.resize (len); - } - - dirlist[count] = dir_ent->d_name; - - count++; - } + dirlist.push_back (dir_ent->d_name); else break; } - dirlist.resize (count); + retval = string_vector (dirlist); } - return dirlist; + return retval; } void