summaryrefslogtreecommitdiffstats
path: root/src/H5Spoint.c
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2019-11-18 19:33:36 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2019-11-18 19:33:36 (GMT)
commit4e12984b77cdd7615843d94f8de8d54db27476ac (patch)
tree7db096e4acbf035781fefbcb1e6868e4ec0ccfed /src/H5Spoint.c
parent4064332a2dc45e591666ce1bff02001239009bb8 (diff)
downloadhdf5-4e12984b77cdd7615843d94f8de8d54db27476ac.zip
hdf5-4e12984b77cdd7615843d94f8de8d54db27476ac.tar.gz
hdf5-4e12984b77cdd7615843d94f8de8d54db27476ac.tar.bz2
Move checking for zero offset in selection adjust calls to the selection callbacks. This makes the
procedure for checking it consistent across selection types and between _s and _u, ensures it is always is performed even when called within the H5S package, and removes the redundant check that would occur when callins H5S_select_adjust_s() from outside the H5S package.
Diffstat (limited to 'src/H5Spoint.c')
-rw-r--r--src/H5Spoint.c104
1 files changed, 63 insertions, 41 deletions
diff --git a/src/H5Spoint.c b/src/H5Spoint.c
index d501a4a..721211e 100644
--- a/src/H5Spoint.c
+++ b/src/H5Spoint.c
@@ -2080,6 +2080,7 @@ done:
static herr_t
H5S__point_adjust_u(H5S_t *space, const hsize_t *offset)
{
+ hbool_t non_zero_offset = FALSE; /* Whether any offset is non-zero */
H5S_pnt_node_t *node; /* Point node */
unsigned rank; /* Dataspace rank */
unsigned u; /* Local index variable */
@@ -2089,28 +2090,38 @@ H5S__point_adjust_u(H5S_t *space, const hsize_t *offset)
HDassert(space);
HDassert(offset);
- /* Iterate through the nodes, checking the bounds on each element */
- node = space->select.sel_info.pnt_lst->head;
- rank = space->extent.rank;
- while(node) {
- /* Adjust each coordinate for point node */
- for(u = 0; u < rank; u++) {
- /* Check for offset moving selection negative */
- HDassert(node->pnt[u] >= offset[u]);
-
- /* Adjust node's coordinate location */
- node->pnt[u] -= offset[u];
- } /* end for */
+ /* Check for an all-zero offset vector */
+ for(u = 0; u < space->extent.rank; u++)
+ if(0 != offset[u]) {
+ non_zero_offset = TRUE;
+ break;
+ } /* end if */
- /* Advance to next point node in selection */
- node = node->next;
- } /* end while */
+ /* Only perform operation if the offset is non-zero */
+ if(non_zero_offset) {
+ /* Iterate through the nodes, checking the bounds on each element */
+ node = space->select.sel_info.pnt_lst->head;
+ rank = space->extent.rank;
+ while(node) {
+ /* Adjust each coordinate for point node */
+ for(u = 0; u < rank; u++) {
+ /* Check for offset moving selection negative */
+ HDassert(node->pnt[u] >= offset[u]);
+
+ /* Adjust node's coordinate location */
+ node->pnt[u] -= offset[u];
+ } /* end for */
+
+ /* Advance to next point node in selection */
+ node = node->next;
+ } /* end while */
- /* update the bound box of the selection */
- for(u = 0; u < rank; u++) {
- space->select.sel_info.pnt_lst->low_bounds[u] -= offset[u];
- space->select.sel_info.pnt_lst->high_bounds[u] -= offset[u];
- } /* end for */
+ /* update the bound box of the selection */
+ for(u = 0; u < rank; u++) {
+ space->select.sel_info.pnt_lst->low_bounds[u] -= offset[u];
+ space->select.sel_info.pnt_lst->high_bounds[u] -= offset[u];
+ } /* end for */
+ } /* end if */
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5S__point_adjust_u() */
@@ -2137,6 +2148,7 @@ H5S__point_adjust_u(H5S_t *space, const hsize_t *offset)
static herr_t
H5S__point_adjust_s(H5S_t *space, const hssize_t *offset)
{
+ hbool_t non_zero_offset = FALSE; /* Whether any offset is non-zero */
H5S_pnt_node_t *node; /* Point node */
unsigned rank; /* Dataspace rank */
unsigned u; /* Local index variable */
@@ -2146,29 +2158,39 @@ H5S__point_adjust_s(H5S_t *space, const hssize_t *offset)
HDassert(space);
HDassert(offset);
- /* Iterate through the nodes, checking the bounds on each element */
- node = space->select.sel_info.pnt_lst->head;
- rank = space->extent.rank;
- while(node) {
- /* Adjust each coordinate for point node */
- for(u = 0; u < rank; u++) {
- /* Check for offset moving selection negative */
- HDassert((hssize_t)node->pnt[u] >= offset[u]);
-
- /* Adjust node's coordinate location */
- node->pnt[u] = (hsize_t)((hssize_t)node->pnt[u] - offset[u]);
- } /* end for */
+ /* Check for an all-zero offset vector */
+ for(u = 0; u < space->extent.rank; u++)
+ if(0 != offset[u]) {
+ non_zero_offset = TRUE;
+ break;
+ } /* end if */
- /* Advance to next point node in selection */
- node = node->next;
- } /* end while */
+ /* Only perform operation if the offset is non-zero */
+ if(non_zero_offset) {
+ /* Iterate through the nodes, checking the bounds on each element */
+ node = space->select.sel_info.pnt_lst->head;
+ rank = space->extent.rank;
+ while(node) {
+ /* Adjust each coordinate for point node */
+ for(u = 0; u < rank; u++) {
+ /* Check for offset moving selection negative */
+ HDassert((hssize_t)node->pnt[u] >= offset[u]);
+
+ /* Adjust node's coordinate location */
+ node->pnt[u] = (hsize_t)((hssize_t)node->pnt[u] - offset[u]);
+ } /* end for */
+
+ /* Advance to next point node in selection */
+ node = node->next;
+ } /* end while */
- /* update the bound box of the selection */
- for(u = 0; u < rank; u++) {
- HDassert((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] >= offset[u]);
- space->select.sel_info.pnt_lst->low_bounds[u] = (hsize_t)((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] - offset[u]);
- space->select.sel_info.pnt_lst->high_bounds[u] = (hsize_t)((hssize_t)space->select.sel_info.pnt_lst->high_bounds[u] - offset[u]);
- } /* end for */
+ /* update the bound box of the selection */
+ for(u = 0; u < rank; u++) {
+ HDassert((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] >= offset[u]);
+ space->select.sel_info.pnt_lst->low_bounds[u] = (hsize_t)((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] - offset[u]);
+ space->select.sel_info.pnt_lst->high_bounds[u] = (hsize_t)((hssize_t)space->select.sel_info.pnt_lst->high_bounds[u] - offset[u]);
+ } /* end for */
+ } /* end if */
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5S__point_adjust_s() */