diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-02-05 16:10:40 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-02-05 16:10:40 (GMT) |
commit | ad6408e3849dae8bbb1fb25597ccd2f44af7cb36 (patch) | |
tree | 6f7b6642bf85a832fdb6f72279af3065e4f49d76 /src | |
parent | 08aa29cd5e6c4900cf6ce31d09ab44470cda0cca (diff) | |
download | hdf5-ad6408e3849dae8bbb1fb25597ccd2f44af7cb36.zip hdf5-ad6408e3849dae8bbb1fb25597ccd2f44af7cb36.tar.gz hdf5-ad6408e3849dae8bbb1fb25597ccd2f44af7cb36.tar.bz2 |
[svn-r8154] Purpose:
Code cleanup
Description:
Minor tweaks, cleanups & optimizations to new bit operation routines.
Platforms tested:
FreeBSD 4.9 (sleipnir)
too minor to require h5committest
Diffstat (limited to 'src')
-rw-r--r-- | src/H5Tbit.c | 35 | ||||
-rw-r--r-- | src/H5Tconv.c | 7 | ||||
-rw-r--r-- | src/H5Tpkg.h | 2 |
3 files changed, 25 insertions, 19 deletions
diff --git a/src/H5Tbit.c b/src/H5Tbit.c index d063137..ef62f31 100644 --- a/src/H5Tbit.c +++ b/src/H5Tbit.c @@ -27,6 +27,7 @@ #include "H5private.h" /*generic functions */ #include "H5Eprivate.h" /*error handling */ #include "H5Iprivate.h" /*ID functions */ +#include "H5MMprivate.h" /* Memory management */ #include "H5Tpkg.h" /*data-type functions */ /* Interface initialization */ @@ -177,36 +178,38 @@ H5T_bit_copy (uint8_t *dst, size_t dst_offset, const uint8_t *src, *------------------------------------------------------------------------- */ void -H5T_bit_shift (uint8_t *buf, hssize_t shift_dist, size_t buf_size) +H5T_bit_shift (uint8_t *buf, ssize_t shift_dist, size_t buf_size) { uint8_t *tmp_buf; size_t buf_size_bit = 8*buf_size; - size_t i; - FUNC_ENTER_NOAPI_NOINIT(H5T_bit_shift); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_bit_shift); + + /* Sanity check */ + assert(buf); + assert(buf_size); if(!shift_dist) goto done; - if(abs(shift_dist) >= buf_size_bit) { - H5T_bit_set (buf, 0, buf_size_bit, FALSE); + if(ABS(shift_dist) >= buf_size_bit) { + HDmemset(buf,0,buf_size); goto done; } - tmp_buf = (uint8_t*)HDcalloc(buf_size, 1); + tmp_buf = (uint8_t*)H5MM_calloc(buf_size); + assert(tmp_buf); /* Shift vector by making copies */ if(shift_dist > 0) /* left shift */ - H5T_bit_copy (tmp_buf, shift_dist, buf, 0, buf_size_bit-shift_dist); - else { /* right shift */ - shift_dist = -shift_dist; - H5T_bit_copy(tmp_buf, 0, buf, shift_dist, buf_size_bit-shift_dist); - } + H5T_bit_copy (tmp_buf, (size_t)shift_dist, buf, 0, (size_t)(buf_size_bit-shift_dist)); + else /* right shift */ + H5T_bit_copy(tmp_buf, 0, buf, (size_t)-shift_dist, (size_t)(buf_size_bit+shift_dist)); /* Copy back the vector */ - for(i=0; i<buf_size; i++) - buf[i] = tmp_buf[i]; + HDmemcpy(buf,tmp_buf,buf_size); - HDfree(tmp_buf); + /* Free temporary buffer */ + H5MM_xfree(tmp_buf); done: FUNC_LEAVE_NOAPI_VOID @@ -558,6 +561,8 @@ H5T_bit_dec(uint8_t *buf, size_t start, size_t size) size_t idx; assert(buf); + assert(size); + assert(start==0); for(idx=0; idx < size/8; idx++) { if(buf[idx] != 0x00) { @@ -591,6 +596,8 @@ H5T_bit_neg(uint8_t *buf, size_t start, size_t size) size_t i; assert(buf); + assert(size); + assert(start==0); for(i=0; i<size/8; i++) buf[i] = ~(buf[i]); diff --git a/src/H5Tconv.c b/src/H5Tconv.c index cd7a301..280f82c 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -2935,7 +2935,6 @@ H5T_conv_i_i (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts, } } else if (src->u.atomic.prec<dst->u.atomic.prec) { H5T_bit_copy (d, dst->u.atomic.offset, s, src->u.atomic.offset, src->u.atomic.prec); - /* Why is it set to TRUE? */ H5T_bit_set (d, dst->u.atomic.offset+src->u.atomic.prec, dst->u.atomic.prec-src->u.atomic.prec, TRUE); } else { H5T_bit_copy (d, dst->u.atomic.offset, s, src->u.atomic.offset, dst->u.atomic.prec); @@ -8468,8 +8467,8 @@ H5T_conv_f_i (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts, /* Allocate enough space for the buffer holding temporary * converted value */ - buf_size = (int)pow(2, src.u.f.esize) / 8 + 1; - int_buf = (uint8_t*)HDcalloc(buf_size, 1); + buf_size = (int)HDpow((double)2.0, (double)src.u.f.esize) / 8 + 1; + int_buf = (uint8_t*)H5MM_calloc(buf_size); /* The conversion loop */ for (elmtno=0; elmtno<nelmts; elmtno++) { @@ -8734,7 +8733,7 @@ H5T_conv_f_i (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts, HDmemset(int_buf, 0, buf_size); } - HDfree(int_buf); + H5MM_xfree(int_buf); break; diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h index e068c25..27fa5da 100644 --- a/src/H5Tpkg.h +++ b/src/H5Tpkg.h @@ -1066,7 +1066,7 @@ H5_DLL herr_t H5T_conv_i32le_f64le(hid_t src_id, hid_t dst_id, /* Bit twiddling functions */ H5_DLL void H5T_bit_copy(uint8_t *dst, size_t dst_offset, const uint8_t *src, size_t src_offset, size_t size); -H5_DLL void H5T_bit_shift(uint8_t *buf, hssize_t shift_dist, size_t buf_size); +H5_DLL void H5T_bit_shift(uint8_t *buf, ssize_t shift_dist, size_t buf_size); H5_DLL void H5T_bit_set(uint8_t *buf, size_t offset, size_t size, hbool_t value); H5_DLL hsize_t H5T_bit_get_d(uint8_t *buf, size_t offset, size_t size); |