octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it OK for genpath to skip all directories beginning with a perio


From: Jaroslav Hajek
Subject: Re: Is it OK for genpath to skip all directories beginning with a period
Date: Thu, 19 Feb 2009 08:50:33 +0100

On Wed, Feb 18, 2009 at 11:53 PM, John Swensen <address@hidden> wrote:
>
> On Feb 18, 2009, at 1:41 PM, John W. Eaton wrote:
>
>> On 18-Feb-2009, John Swensen wrote:
>>
>> | There is already a FIXME comment in the sources along the lines of the
>> | skipping method you suggested, but that is also non-compatible behavior.
>>
>> Sure, but then at least the user has some easy way to control the
>> behavior, and we could set the defautl to be compatible.
>>
>> jwe
>
> Here is an updated patch as requested.  It adds an optional extra parameter
> to the genpath() function in Octave to allow the user to specify a colon
> separated list of directories to exclude.  I also made to changes to the
> load-path.cc file to re-use the split_path() function for both splitting
> paths and splitting other strings with a delimiter.  Because of the use of
> the split_path function, I also changed the C++ version of genpath from
> using an string_vector to an std::list<std::string>.  Let me know if you
> think it needs any other changes.
>
> John Swensen
>
>

Hi John,

the use of string_vector is preferable to std::list<std::string>,
especially as a function result. The reason is that unlike standard
STL containers, Array<T> descendants such as string_vector implement
shallow copying using reference counting.
Thus, something like

string_vector str_vec = string_vector_func ()  // returns string_vector

is a constant-time operation, while

std::list<std::string> str_list = string_list_func () // returns
std::list<std::string>

is a linear-time operation (will involve a copy of the list, unless
the compiler is *VERY* smart).

To put it shortly, the STL containers are ill-suited to be passed by
value, they should be passed by references. A straightforward
reference-counting implementation of most STL containers would, in
fact, violate the standard.

std::string is an exception; the complexity and iterator validity
requirements for std::string were intentionally weakened to the point
allowing a reference-counting implementation (and most compilers do
so, though it is not mandated).

Since string_vector allows itself to be constructed from
std::list<std::string>, I think the best option is to return
string_vector from split_string. Please find attached a revision of
your patch which does so (otherwise, I wasn't following the point of
the patch, so I won't apply it myself).

One more small comment: the ChangeLog entry should go in src/ChangeLog
and maybe could be a little more descriptive (I haven't fixed this).

regards

-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

Attachment: genpath_skip_rev3.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]