# HG changeset patch # User jwe # Date 825900014 0 # Node ID 95e952f72d66d5a1c6b779f1a0227782741ef84d # Parent c1ffef39e94af964c8f936a3bb0b5f07a4085e42 [project @ 1996-03-04 00:33:32 by jwe] diff --git a/liboctave/Array-C.cc b/liboctave/Array-C.cc --- a/liboctave/Array-C.cc +++ b/liboctave/Array-C.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate Arrays of Complex values. #include "oct-cmplx.h" diff --git a/liboctave/Array-ch.cc b/liboctave/Array-ch.cc --- a/liboctave/Array-ch.cc +++ b/liboctave/Array-ch.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate Arrays of char values. #include "Array.h" diff --git a/liboctave/Array-d.cc b/liboctave/Array-d.cc --- a/liboctave/Array-d.cc +++ b/liboctave/Array-d.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate Arrays of double values. #include "Array.h" diff --git a/liboctave/Array-i.cc b/liboctave/Array-i.cc --- a/liboctave/Array-i.cc +++ b/liboctave/Array-i.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate Arrays of integer values. #include "Array.h" diff --git a/liboctave/Array-s.cc b/liboctave/Array-s.cc --- a/liboctave/Array-s.cc +++ b/liboctave/Array-s.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate Arrays of short int values. #include "Array.h" diff --git a/liboctave/Array-str.cc b/liboctave/Array-str.cc --- a/liboctave/Array-str.cc +++ b/liboctave/Array-str.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate Arrays of strings. #include "Array.h" diff --git a/liboctave/Array.cc b/liboctave/Array.cc --- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -94,47 +94,6 @@ } template -T& -Array::checkelem (int n) -{ - if (n < 0 || n >= rep->length ()) - { - (*current_liboctave_error_handler) ("range error"); - static T foo; - return foo; - } - return elem (n); -} - -template -T -Array::elem (int n) const -{ - return rep->elem (n); -} - -template -T -Array::checkelem (int n) const -{ - if (n < 0 || n >= rep->length ()) - { - (*current_liboctave_error_handler) ("range error"); - T foo; - static T *bar = &foo; - return foo; - } - return elem (n); -} - -template -T -Array::operator () (int n) const -{ - return checkelem (n); -} - -template void Array::resize (int n) { diff --git a/liboctave/Array.h b/liboctave/Array.h --- a/liboctave/Array.h +++ b/liboctave/Array.h @@ -82,6 +82,15 @@ } }; + void make_unique (void) + { + if (rep->count > 1) + { + --rep->count; + rep = new ArrayRep (*rep); + } + } + #ifdef HEAVYWEIGHT_INDEXING idx_vector *idx; int max_indices; @@ -148,24 +157,55 @@ int capacity (void) const { return rep->length (); } int length (void) const { return rep->length (); } + // XXX FIXME XXX -- would be nice to fix this so that we don't + // unnecessarily force a copy, but that is not so easy, and I see no + // clean way to do it. + T& elem (int n) { - if (rep->count > 1) - { - --rep->count; - rep = new ArrayRep (*rep); - } + make_unique (); return rep->elem (n); } - T& checkelem (int n); + T& Array::checkelem (int n) + { + if (n < 0 || n >= rep->length ()) + { + (*current_liboctave_error_handler) ("range error"); + static T foo; + return foo; + } + else + return elem (n); + } + +#if defined (NO_BOUNDS_CHECKING) + T& operator () (int n) { return elem (n); } +#else T& operator () (int n) { return checkelem (n); } +#endif + + T Array::elem (int n) const { return rep->elem (n); } - T elem (int n) const; - T checkelem (int n) const; - T operator () (int n) const; + T Array::checkelem (int n) const + { + if (n < 0 || n >= rep->length ()) + { + (*current_liboctave_error_handler) ("range error"); + T foo; + static T *bar = &foo; + return foo; + } + return elem (n); + } - // No checking. +#if defined (NO_BOUNDS_CHECKING) + T Array::operator () (int n) const { return elem (n); } +#else + T Array::operator () (int n) const { return checkelem (n); } +#endif + + // No checking, even for multiple references, ever. T& xelem (int n) { return rep->elem (n); } T xelem (int n) const { return rep->elem (n); } diff --git a/liboctave/Array2.cc b/liboctave/Array2.cc --- a/liboctave/Array2.cc +++ b/liboctave/Array2.cc @@ -45,54 +45,6 @@ // Two dimensional array class. template -T& -Array2::checkelem (int i, int j) -{ - if (i < 0 || j < 0 || i >= d1 || j >= d2) - { - (*current_liboctave_error_handler) ("range error"); - static T foo; - return foo; - } - return Array::elem (d1*j+i); -} - -template -T -Array2::elem (int i, int j) const -{ - return Array::elem (d1*j+i); -} - -template -T -Array2::checkelem (int i, int j) const -{ - if (i < 0 || j < 0 || i >= d1 || j >= d2) - { - (*current_liboctave_error_handler) ("range error"); - T foo; - static T *bar = &foo; - return foo; - } - return Array::elem (d1*j+i); -} - -template -T -Array2::operator () (int i, int j) const -{ - if (i < 0 || j < 0 || i >= d1 || j >= d2) - { - (*current_liboctave_error_handler) ("range error"); - T foo; - static T *bar = &foo; - return foo; - } - return Array::elem (d1*j+i); -} - -template void Array2::resize (int r, int c) { diff --git a/liboctave/Array2.h b/liboctave/Array2.h --- a/liboctave/Array2.h +++ b/liboctave/Array2.h @@ -116,14 +116,47 @@ int columns (void) const { return d2; } T& elem (int i, int j) { return Array::elem (d1*j+i); } - T& checkelem (int i, int j); + + T& checkelem (int i, int j) + { + if (i < 0 || j < 0 || i >= d1 || j >= d2) + { + (*current_liboctave_error_handler) ("range error"); + static T foo; + return foo; + } + else + return elem (i, j); + } + +#if defined (NO_BOUNDS_CHECKING) + T& operator () (int i, int j) { return elem (i, j); } +#else T& operator () (int i, int j) { return checkelem (i, j); } +#endif + + T elem (int i, int j) const { return Array::elem (d1*j+i); } - T elem (int i, int j) const; - T checkelem (int i, int j) const; - T operator () (int i, int j) const; + T checkelem (int i, int j) const + { + if (i < 0 || j < 0 || i >= d1 || j >= d2) + { + (*current_liboctave_error_handler) ("range error"); + T foo; + static T *bar = &foo; + return foo; + } + else + return elem (i, j); + } - // No checking. +#if defined (NO_BOUNDS_CHECKING) + T operator () (int i, int j) const { return elem (i, j); } +#else + T operator () (int i, int j) const { return checkelem (i, j); } +#endif + + // No checking of any kind, ever. T& xelem (int i, int j) { return Array::xelem (d1*j+i); } T xelem (int i, int j) const { return Array::xelem (d1*j+i); } diff --git a/liboctave/MArray-C.cc b/liboctave/MArray-C.cc --- a/liboctave/MArray-C.cc +++ b/liboctave/MArray-C.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate MArrays of Complex values. #include "oct-cmplx.h" diff --git a/liboctave/MArray-ch.cc b/liboctave/MArray-ch.cc --- a/liboctave/MArray-ch.cc +++ b/liboctave/MArray-ch.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate MArrays of char values. #include "MArray.h" diff --git a/liboctave/MArray-d.cc b/liboctave/MArray-d.cc --- a/liboctave/MArray-d.cc +++ b/liboctave/MArray-d.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate MArrays of double values. #include "MArray.h" diff --git a/liboctave/MArray-i.cc b/liboctave/MArray-i.cc --- a/liboctave/MArray-i.cc +++ b/liboctave/MArray-i.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate MArrays of int values. #include "MArray.h" diff --git a/liboctave/MArray-s.cc b/liboctave/MArray-s.cc --- a/liboctave/MArray-s.cc +++ b/liboctave/MArray-s.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif + // Instantiate MArrays of short int values. #include "MArray.h" diff --git a/liboctave/MDiagArray2.cc b/liboctave/MDiagArray2.cc --- a/liboctave/MDiagArray2.cc +++ b/liboctave/MDiagArray2.cc @@ -47,7 +47,8 @@ { (*current_liboctave_error_handler) ("nonconformant array operator += attempted"); - return MDiagArray2 (); + static MDiagArray2 foo; + return foo; } else { @@ -67,7 +68,8 @@ { (*current_liboctave_error_handler) ("nonconformant array operator -= attempted"); - return MDiagArray2 (); + static MDiagArray2 foo; + return foo; } else { diff --git a/liboctave/pathsearch.cc b/liboctave/pathsearch.cc --- a/liboctave/pathsearch.cc +++ b/liboctave/pathsearch.cc @@ -131,7 +131,7 @@ retval.resize (count); for (int i = 0; i < count; i++) - retval[i] = *tmp[i]; + retval[i] = tmp[i]; } return retval;