# HG changeset patch # User John W. Eaton # Date 1227166895 -3600 # Node ID 53e846af744d0cc2aa6bfdde3f7ffb2a92520701 # Parent 3342d1a7c4c95d1216386568417f5591d9cd3fed dir-ops.cc (dir_entry::read): use std::list to cache names before converting to string_vector diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -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-10-09 Jaroslav Hajek * oct-sort.cc (octave_sort::merge_getmem, diff --git a/liboctave/dir-ops.cc b/liboctave/dir-ops.cc --- a/liboctave/dir-ops.cc +++ b/liboctave/dir-ops.cc @@ -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