changeset 10358:72fab01e5d68

improve some size_t queries
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 25 Feb 2010 12:55:13 +0100
parents 7658cd4bdcf2
children ec05728ce7f0
files liboctave/Array.h liboctave/ChangeLog liboctave/DiagArray2.h liboctave/PermMatrix.h liboctave/Sparse.h liboctave/oct-mem.h
diffstat 6 files changed, 25 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array.h
+++ b/liboctave/Array.h
@@ -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<size_t> (numel ()) * sizeof (T); }
 
   // Return a const-reference so that dims ()(i) works efficiently.
   const dim_vector& dims (void) const { return dimensions; }
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,3 +1,12 @@
+
+2010-02-25  Jaroslav Hajek  <highegg@gmail.com>
+
+	* oct-mem.h (copy_or_memcpy, fill_or_memset, no_ctor_new): Accept
+	size_t rather than octave_idx_type.
+	* Array.h (Array<T>::byte_size): Correct calculation.
+	* DiagArray2.h (DiagArray2<T>::byte_size): Call inherited byte_size.
+	* PermMatrix.h (PermMatrix::byte_size): Ditto.
+
 2010-02-25  Jaroslav Hajek  <highegg@gmail.com>
 
 	* str-vec.h (string_vector::string_vector): Use (n, 1).
--- a/liboctave/DiagArray2.h
+++ b/liboctave/DiagArray2.h
@@ -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<T>::byte_size (); }
 
   dim_vector dims (void) const { return dim_vector (d1, d2); }
 
--- a/liboctave/PermMatrix.h
+++ b/liboctave/PermMatrix.h
@@ -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<octave_idx_type>::byte_size (); }
 
   dim_vector dims (void) const { return dim_vector (dim1 (), dim2 ()); }
 
--- a/liboctave/Sparse.h
+++ b/liboctave/Sparse.h
@@ -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<size_t>(cols () + 1) * sizeof (octave_idx_type)
+              + static_cast<size_t> (capacity ()) * (sizeof (T) + sizeof (octave_idx_type))); 
+    }
 
   dim_vector dims (void) const { return dimensions; }
 
--- a/liboctave/oct-mem.h
+++ b/liboctave/oct-mem.h
@@ -39,11 +39,11 @@
 // Unaliased copy. This boils down to memcpy, even for octave_int and complex types.
 
 template <class 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::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 <class 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)
 { std::fill_n (dest, n, value); }
 
 template <class T>
@@ -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 <class T>
-inline T *no_ctor_new (octave_idx_type n)
+inline T *no_ctor_new (size_t n)
 { return new T[n]; }
 template <class T>
 inline void no_ctor_delete (T *ptr)
@@ -124,7 +124,7 @@
 
 #define DEFINE_POD_NEW_DELETE(T) \
 template <> \
-inline T *no_ctor_new<T > (octave_idx_type n) \
+inline T *no_ctor_new<T > (size_t n) \
 { return reinterpret_cast<T *> (new char[n * sizeof (T)]); } \
 template <> \
 inline void no_ctor_delete<T > (T *ptr) \