diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-06-09 18:07:36 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-06-09 18:07:36 (GMT) |
commit | 70044f9c88cb983163b533d39a91a022c42e114c (patch) | |
tree | af98b7ddded1200e319b25fa8f69be1d6f7babc8 /src/H5Dio.c | |
parent | a8e09cbc3eca78877733309a64615b0c96979c1e (diff) | |
download | hdf5-70044f9c88cb983163b533d39a91a022c42e114c.zip hdf5-70044f9c88cb983163b533d39a91a022c42e114c.tar.gz hdf5-70044f9c88cb983163b533d39a91a022c42e114c.tar.bz2 |
[svn-r8636] Purpose:
Code optimization
Description:
Don't allocate conversion buffer larger than the user's buffer.
Platforms tested:
Solaris 2.7 (arabica)
FreeBSD 4.10 (sleipnir) w/parallel
too minor to require h5committest
Diffstat (limited to 'src/H5Dio.c')
-rw-r--r-- | src/H5Dio.c | 102 |
1 files changed, 65 insertions, 37 deletions
diff --git a/src/H5Dio.c b/src/H5Dio.c index 77b9926..9d8ef7d 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -1042,11 +1042,10 @@ done: * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t -H5D_contig_read(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, - const H5S_t *mem_space, const H5S_t *file_space, H5T_path_t *tpath, - H5S_conv_t *sconv, +H5D_contig_read(hsize_t nelmts, H5D_t *dataset, + const H5T_t *mem_type, const H5S_t *mem_space, + const H5S_t *file_space, H5T_path_t *tpath, H5S_conv_t *sconv, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, hid_t src_id, hid_t dst_id, void *buf/*out*/) { @@ -1056,6 +1055,7 @@ H5D_contig_read(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, #endif size_t src_type_size; /*size of source type */ size_t dst_type_size; /*size of destination type*/ + size_t max_type_size; /* Size of largest source/destination type */ size_t target_size; /*desired buffer size */ hsize_t request_nelmts; /*requested strip mine */ H5S_sel_iter_t mem_iter; /*memory selection iteration info*/ @@ -1108,21 +1108,29 @@ H5D_contig_read(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, } /* end if */ /* - * This is the general case(type conversion). + * This is the general case (type conversion, usually). */ + if(nelmts==0) + HGOTO_DONE(SUCCEED) /* Compute element sizes and other parameters */ src_type_size = H5T_get_size(dataset->type); dst_type_size = H5T_get_size(mem_type); + max_type_size = MAX(src_type_size, dst_type_size); target_size = dxpl_cache->max_temp_buf; /* XXX: This could cause a problem if the user sets their buffer size * to the same size as the default, and then the dataset elements are * too large for the buffer... - QAK */ - if(target_size==H5D_XFER_MAX_TEMP_BUF_DEF && - target_size<MAX(src_type_size, dst_type_size)) - target_size = MAX(src_type_size, dst_type_size); - request_nelmts = target_size / MAX(src_type_size, dst_type_size); + if(target_size==H5D_XFER_MAX_TEMP_BUF_DEF) { + /* If the buffer is too small to hold even one element, make it bigger */ + if(target_size<max_type_size) + target_size = max_type_size; + /* If the buffer is too large to hold all the elements, make it smaller */ + else if(target_size>(nelmts*max_type_size)) + target_size=(nelmts*max_type_size); + } /* end if */ + request_nelmts = target_size / max_type_size; /* Sanity check elements in temporary buffer */ if (request_nelmts==0) @@ -1286,9 +1294,9 @@ done: * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t -H5D_contig_write(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, +H5D_contig_write(hsize_t nelmts, H5D_t *dataset, + const H5T_t *mem_type, const H5S_t *mem_space, const H5S_t *file_space, H5T_path_t *tpath, H5S_conv_t *sconv, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, hid_t src_id, hid_t dst_id, const void *buf) @@ -1299,6 +1307,7 @@ H5D_contig_write(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5 #endif size_t src_type_size; /*size of source type */ size_t dst_type_size; /*size of destination type*/ + size_t max_type_size; /* Size of largest source/destination type */ size_t target_size; /*desired buffer size */ hsize_t request_nelmts; /*requested strip mine */ H5S_sel_iter_t mem_iter; /*memory selection iteration info*/ @@ -1347,19 +1356,27 @@ H5D_contig_write(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5 /* * This is the general case. */ + if(nelmts==0) + HGOTO_DONE(SUCCEED) /* Compute element sizes and other parameters */ src_type_size = H5T_get_size(mem_type); dst_type_size = H5T_get_size(dataset->type); + max_type_size = MAX(src_type_size, dst_type_size); target_size = dxpl_cache->max_temp_buf; /* XXX: This could cause a problem if the user sets their buffer size * to the same size as the default, and then the dataset elements are * too large for the buffer... - QAK */ - if(target_size==H5D_XFER_MAX_TEMP_BUF_DEF && - target_size<MAX(src_type_size, dst_type_size)) - target_size = MAX(src_type_size, dst_type_size); - request_nelmts = target_size / MAX (src_type_size, dst_type_size); + if(target_size==H5D_XFER_MAX_TEMP_BUF_DEF) { + /* If the buffer is too small to hold even one element, make it bigger */ + if(target_size<max_type_size) + target_size = max_type_size; + /* If the buffer is too large to hold all the elements, make it smaller */ + else if(target_size>(nelmts*max_type_size)) + target_size=(nelmts*max_type_size); + } /* end if */ + request_nelmts = target_size / max_type_size; /* Sanity check elements in temporary buffer */ if (request_nelmts==0) @@ -1523,13 +1540,9 @@ done: * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t -H5D_chunk_read(hsize_t -#ifdef NDEBUG -UNUSED -#endif /* NDEBUG */ - nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, +H5D_chunk_read(hsize_t nelmts, H5D_t *dataset, + const H5T_t *mem_type, const H5S_t *mem_space, const H5S_t *file_space, H5T_path_t *tpath, H5S_conv_t *sconv, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, hid_t src_id, hid_t dst_id, void *buf/*out*/) @@ -1542,6 +1555,7 @@ UNUSED #endif size_t src_type_size; /*size of source type */ size_t dst_type_size; /*size of destination type*/ + size_t max_type_size; /* Size of largest source/destination type */ size_t target_size; /*desired buffer size */ hsize_t request_nelmts; /*requested strip mine */ hsize_t smine_start; /*strip mine start loc */ @@ -1617,21 +1631,29 @@ UNUSED } /* end if */ /* - * This is the general case(type conversion). + * This is the general case (type conversion, usually). */ + if(nelmts==0) + HGOTO_DONE(SUCCEED) /* Compute element sizes and other parameters */ src_type_size = H5T_get_size(dataset->type); dst_type_size = H5T_get_size(mem_type); + max_type_size = MAX(src_type_size, dst_type_size); target_size = dxpl_cache->max_temp_buf; /* XXX: This could cause a problem if the user sets their buffer size * to the same size as the default, and then the dataset elements are * too large for the buffer... - QAK */ - if(target_size==H5D_XFER_MAX_TEMP_BUF_DEF && - target_size<MAX(src_type_size, dst_type_size)) - target_size = MAX(src_type_size, dst_type_size); - request_nelmts = target_size / MAX (src_type_size, dst_type_size); + if(target_size==H5D_XFER_MAX_TEMP_BUF_DEF) { + /* If the buffer is too small to hold even one element, make it bigger */ + if(target_size<max_type_size) + target_size = max_type_size; + /* If the buffer is too large to hold all the elements, make it smaller */ + else if(target_size>(nelmts*max_type_size)) + target_size=(nelmts*max_type_size); + } /* end if */ + request_nelmts = target_size / max_type_size; /* Sanity check elements in temporary buffer */ if (request_nelmts==0) @@ -1834,13 +1856,9 @@ done: * *------------------------------------------------------------------------- */ -/* ARGSUSED */ static herr_t -H5D_chunk_write(hsize_t -#ifdef NDEBUG -UNUSED -#endif /* NDEBUG */ -nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, +H5D_chunk_write(hsize_t nelmts, H5D_t *dataset, + const H5T_t *mem_type, const H5S_t *mem_space, const H5S_t *file_space, H5T_path_t *tpath, H5S_conv_t *sconv, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, hid_t src_id, hid_t dst_id, const void *buf) @@ -1853,6 +1871,7 @@ nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, #endif size_t src_type_size; /*size of source type */ size_t dst_type_size; /*size of destination type*/ + size_t max_type_size; /* Size of largest source/destination type */ size_t target_size; /*desired buffer size */ hsize_t request_nelmts; /*requested strip mine */ hsize_t smine_start; /*strip mine start loc */ @@ -1966,21 +1985,29 @@ nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, #endif /* QAK */ /* - * This is the general case(type conversion). + * This is the general case (type conversion, usually). */ + if(nelmts==0) + HGOTO_DONE(SUCCEED) /* Compute element sizes and other parameters */ src_type_size = H5T_get_size(mem_type); dst_type_size = H5T_get_size(dataset->type); + max_type_size = MAX(src_type_size, dst_type_size); target_size = dxpl_cache->max_temp_buf; /* XXX: This could cause a problem if the user sets their buffer size * to the same size as the default, and then the dataset elements are * too large for the buffer... - QAK */ - if(target_size==H5D_XFER_MAX_TEMP_BUF_DEF && - target_size<MAX(src_type_size, dst_type_size)) - target_size = MAX(src_type_size, dst_type_size); - request_nelmts = target_size / MAX (src_type_size, dst_type_size); + if(target_size==H5D_XFER_MAX_TEMP_BUF_DEF) { + /* If the buffer is too small to hold even one element, make it bigger */ + if(target_size<max_type_size) + target_size = max_type_size; + /* If the buffer is too large to hold all the elements, make it smaller */ + else if(target_size>(nelmts*max_type_size)) + target_size=(nelmts*max_type_size); + } /* end if */ + request_nelmts = target_size / max_type_size; /* Sanity check elements in temporary buffer */ if (request_nelmts==0) @@ -3186,3 +3213,4 @@ H5D_chunk_mem_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize_ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5D_chunk_mem_cb() */ + |