Mercurial > hg > octave-shane
changeset 9400:df1ea906c1c4
a slight speed-up in oct-sort.cc
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 26 Jun 2009 11:40:34 +0200 |
parents | a5f6b5800f86 |
children | 6c421f2355b5 |
files | liboctave/ChangeLog liboctave/oct-sort.cc |
diffstat | 2 files changed, 19 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2009-06-26 Jaroslav Hajek <highegg@gmail.com> + + * oct-sort.cc (octave_sort<T>::lookup_merge<Comp>): Slightly speed-up + the merge case. + 2009-06-26 Jaroslav Hajek <highegg@gmail.com> * oct-sort.cc (octave_sort<T>::lookup_merge<Comp>): Fix lower-part
--- a/liboctave/oct-sort.cc +++ b/liboctave/oct-sort.cc @@ -1806,13 +1806,22 @@ { // Do a linear merge. octave_idx_type i = lo, j = 0; - while (j != nvalues && i < hi) + + if (j != nvalues && i != hi) { - if (comp (values[j], data[i])) - idx[j++] = i; - else - i++; + while (true) + { + if (comp (values[j], data[i])) + { + idx[j] = i; + if (++j == nvalues) + break; + } + else if (++i == hi) + break; + } } + while (j != nvalues) idx[j++] = i; }