# HG changeset patch # User Jaroslav Hajek # Date 1267098913 -3600 # Node ID 72fab01e5d68390bfb37f30aa630f479964fa8fb # Parent 7658cd4bdcf280612290a08e8b80a105673a0e47 improve some size_t queries diff -r 7658cd4bdcf2 -r 72fab01e5d68 liboctave/Array.h --- a/liboctave/Array.h Thu Feb 25 11:11:45 2010 +0100 +++ b/liboctave/Array.h Thu Feb 25 12:55:13 2010 +0100 @@ -343,7 +343,7 @@ octave_idx_type columns (void) const { return dim2 (); } octave_idx_type pages (void) const { return dim3 (); } - size_t byte_size (void) const { return numel () * sizeof (T); } + size_t byte_size (void) const { return static_cast (numel ()) * sizeof (T); } // Return a const-reference so that dims ()(i) works efficiently. const dim_vector& dims (void) const { return dimensions; } diff -r 7658cd4bdcf2 -r 72fab01e5d68 liboctave/ChangeLog --- a/liboctave/ChangeLog Thu Feb 25 11:11:45 2010 +0100 +++ b/liboctave/ChangeLog Thu Feb 25 12:55:13 2010 +0100 @@ -1,3 +1,12 @@ + +2010-02-25 Jaroslav Hajek + + * oct-mem.h (copy_or_memcpy, fill_or_memset, no_ctor_new): Accept + size_t rather than octave_idx_type. + * Array.h (Array::byte_size): Correct calculation. + * DiagArray2.h (DiagArray2::byte_size): Call inherited byte_size. + * PermMatrix.h (PermMatrix::byte_size): Ditto. + 2010-02-25 Jaroslav Hajek * str-vec.h (string_vector::string_vector): Use (n, 1). diff -r 7658cd4bdcf2 -r 72fab01e5d68 liboctave/DiagArray2.h --- a/liboctave/DiagArray2.h Thu Feb 25 11:11:45 2010 +0100 +++ b/liboctave/DiagArray2.h Thu Feb 25 12:55:13 2010 +0100 @@ -148,7 +148,7 @@ octave_idx_type nelem (void) const { return dim1 () * dim2 (); } octave_idx_type numel (void) const { return nelem (); } - size_t byte_size (void) const { return length () * sizeof (T); } + size_t byte_size (void) const { return Array::byte_size (); } dim_vector dims (void) const { return dim_vector (d1, d2); } diff -r 7658cd4bdcf2 -r 72fab01e5d68 liboctave/PermMatrix.h --- a/liboctave/PermMatrix.h Thu Feb 25 11:11:45 2010 +0100 +++ b/liboctave/PermMatrix.h Thu Feb 25 12:55:13 2010 +0100 @@ -63,7 +63,8 @@ octave_idx_type nelem (void) const { return dim1 () * dim2 (); } octave_idx_type numel (void) const { return nelem (); } - size_t byte_size (void) const { return perm_length () * sizeof (octave_idx_type); } + size_t byte_size (void) const + { return Array::byte_size (); } dim_vector dims (void) const { return dim_vector (dim1 (), dim2 ()); } diff -r 7658cd4bdcf2 -r 72fab01e5d68 liboctave/Sparse.h --- a/liboctave/Sparse.h Thu Feb 25 11:11:45 2010 +0100 +++ b/liboctave/Sparse.h Thu Feb 25 12:55:13 2010 +0100 @@ -263,8 +263,12 @@ ret++; return ret; } - size_t byte_size (void) const { return (cols () + 1) * sizeof (octave_idx_type) + - capacity () * (sizeof (T) + sizeof (octave_idx_type)); } + + size_t byte_size (void) const + { + return (static_cast(cols () + 1) * sizeof (octave_idx_type) + + static_cast (capacity ()) * (sizeof (T) + sizeof (octave_idx_type))); + } dim_vector dims (void) const { return dimensions; } diff -r 7658cd4bdcf2 -r 72fab01e5d68 liboctave/oct-mem.h --- a/liboctave/oct-mem.h Thu Feb 25 11:11:45 2010 +0100 +++ b/liboctave/oct-mem.h Thu Feb 25 12:55:13 2010 +0100 @@ -39,11 +39,11 @@ // Unaliased copy. This boils down to memcpy, even for octave_int and complex types. template -inline void copy_or_memcpy (octave_idx_type n, const T *src, T *dest) +inline void copy_or_memcpy (size_t n, const T *src, T *dest) { std::copy (src, src + n, dest); } #define DEFINE_POD_UCOPY(T) \ -inline void copy_or_memcpy (octave_idx_type n, const T *src, T *dest) \ +inline void copy_or_memcpy (size_t n, const T *src, T *dest) \ { std::memcpy (dest, src, n * sizeof (T)); } DEFINE_POD_UCOPY (double) @@ -66,7 +66,7 @@ // Fill by value, with a check for zero. This boils down to memset if value is // a POD zero. template -inline void fill_or_memset (octave_idx_type n, const T& value, T *dest) +inline void fill_or_memset (size_t n, const T& value, T *dest) { std::fill_n (dest, n, value); } template @@ -88,7 +88,7 @@ { return value.value () == T(); } #define DEFINE_POD_FILL(T) \ -inline void fill_or_memset (octave_idx_type n, const T& value, T *dest) \ +inline void fill_or_memset (size_t n, const T& value, T *dest) \ { \ if (helper_is_zero_mem (value)) \ std::memset (dest, 0, n * sizeof (T)); \ @@ -116,7 +116,7 @@ // Uninitialized allocation. Will not initialize memory for complex and octave_int. // Memory allocated by octave_new should be freed by octave_delete. template -inline T *no_ctor_new (octave_idx_type n) +inline T *no_ctor_new (size_t n) { return new T[n]; } template inline void no_ctor_delete (T *ptr) @@ -124,7 +124,7 @@ #define DEFINE_POD_NEW_DELETE(T) \ template <> \ -inline T *no_ctor_new (octave_idx_type n) \ +inline T *no_ctor_new (size_t n) \ { return reinterpret_cast (new char[n * sizeof (T)]); } \ template <> \ inline void no_ctor_delete (T *ptr) \