Mercurial > hg > octave-nkf
changeset 10133:2e4fc7fdba15
optimize strfind with 1 or 2 characters
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 19 Jan 2010 13:24:54 +0100 |
parents | aa0f575cf39b |
children | be13fa20656a |
files | src/ChangeLog src/DLD-FUNCTIONS/strfind.cc |
diffstat | 2 files changed, 35 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2010-01-19 Jaroslav Hajek <highegg@gmail.com> + + * DLD-FUNCTIONS/strfind.cc: Optimize searching for 1 or 2 characters. + 2010-01-18 John W. Eaton <jwe@octave.org> * oct-parse.yy (fcn_end): Allow EOF as end of function if
--- a/src/DLD-FUNCTIONS/strfind.cc +++ b/src/DLD-FUNCTIONS/strfind.cc @@ -70,8 +70,38 @@ // We'll use deque because it typically has the most favorable properties for // the operation we need. std::deque<octave_idx_type> accum; - if (n >= m) + if (m == 1) + { + // Looking for a single character. + for (octave_idx_type i = 0; i < n; i++) + { + if (y[i] == x[0]) + accum.push_back (i); + } + } + else if (m == 2) { + // Two characters. + if (overlaps) + { + for (octave_idx_type i = 0; i < n-1; i++) + { + if (y[i] == x[0] && y[i+1] == x[1]) + accum.push_back (i); + } + } + else + { + for (octave_idx_type i = 0; i < n-1; i++) + { + if (y[i] == x[0] && y[i+1] == x[1]) + accum.push_back (i++); + } + } + } + else if (n >= m) + { + // General case. octave_idx_type j = 0; if (overlaps)