[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Some strfns.cc loose ends
From: |
Daniel J Sebald |
Subject: |
Some strfns.cc loose ends |
Date: |
Wed, 25 Jul 2012 19:21:19 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16 |
Given some of the conversations at OctConf, here are some questions to
resolve some loose ends in the strfns.cc string functions code.
As a summary, the strncmp and related functions will compare two arrays
of strings (or, I assume an array and a single string) via the array_op.
If an argument is a cell, then there is more tests and work for
various scenarios. For example, there is a test:
if (cell_val.is_cellstr ())
Recall our discussion at OctConf where we wondered about the speed of
iscellstr. Is the is_cellstr() above related to that? In other words
is there a possible speed issue here?
Also recall the solution was a flag variable associated with the cell,
or as proposed by Max caching the type in some cases.
Now, look at the way the
// FIXME: should we warn here?
for (octave_idx_type i = 0; i < r; i++)
{
if (cell(i).is_string ())
output(i) = str_op (str[i],
cell(i).string_value (), n);
}
If there is a nonstring in the cell, then Octave will just skip over the
comparison. That is why there is a FIXME, because that really doesn't
feel like the right thing to do. I think this line
boolNDArray output (cell_val.dims (), false);
means that output is predefined as false (i.e., are not the same), so
there is no uncertainty about skipping over the test. But still, it
seems someone uncomforting to NOT issue an error.
So what do people think about just iterating through the array and
testing whether the element is a string. If not, issue an error and
break to the command line? That way, we could leave out the
cell_val.is_cellstr() member function test if it is slow. (Or, if we
plan to optimize is_cellstr() for speed in the future it could be left in.)
In any case, thoughts on getting rid of the FIXME by simply error-ing
out when the element is a non-string as opposed to skipping and
indicating 0?
Dan
- Some strfns.cc loose ends,
Daniel J Sebald <=