# HG changeset patch # User John W. Eaton # Date 1226970263 18000 # Node ID 545b9f62adcfc8abc2216b75afc3b1e585f6fc2e # Parent b93ac0586e4bca87c524fceda96600f4df29986c dir-ops.cc (dir_entry::read): use std::list to cache names before converting to string_vector diff -r b93ac0586e4b -r 545b9f62adcf liboctave/ChangeLog --- a/liboctave/ChangeLog Mon Nov 17 11:38:39 2008 +0100 +++ b/liboctave/ChangeLog Mon Nov 17 20:04:23 2008 -0500 @@ -1,3 +1,8 @@ +2008-11-17 John W. Eaton + + * dir-ops.cc (dir_entry::read): Use std::list to + cache names before converting to string_vector. + 2008-11-14 David Bateman * Array2.h (Array2 Array2::index): Correct use of diff -r b93ac0586e4b -r 545b9f62adcf liboctave/dir-ops.cc --- a/liboctave/dir-ops.cc Mon Nov 17 11:38:39 2008 +0100 +++ b/liboctave/dir-ops.cc Mon Nov 17 20:04:23 2008 -0500 @@ -28,6 +28,9 @@ #include #include +#include +#include + #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 dirlist; struct dirent *dir_ent; while ((dir_ent = readdir (static_cast (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