From 975a360db28abb7050dc7bf0e0c2b0dac466badd Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Mon, 18 Nov 2019 13:33:36 -0600 Subject: 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. --- src/H5Shyper.c | 55 ++++++++++++++++++------------ src/H5Spoint.c | 104 ++++++++++++++++++++++++++++++++++---------------------- src/H5Sselect.c | 28 +++------------ 3 files changed, 100 insertions(+), 87 deletions(-) diff --git a/src/H5Shyper.c b/src/H5Shyper.c index a76812d..ab06eff 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -6477,39 +6477,50 @@ H5S__hyper_adjust_u_helper(H5S_hyper_span_info_t *spans, unsigned rank, static herr_t H5S__hyper_adjust_u(H5S_t *space, const hsize_t *offset) { + hbool_t non_zero_offset = FALSE; /* Whether any offset is non-zero */ + unsigned u; /* Local index variable */ + FUNC_ENTER_STATIC_NOERR /* Sanity check */ HDassert(space); HDassert(offset); - /* Subtract the offset from the "regular" coordinates, if they exist */ - /* (No need to rebuild the dimension info yet -QAK) */ - if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { - unsigned u; /* Local index variable */ + /* 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 */ - for(u = 0; u < space->extent.rank; u++) { - HDassert(space->select.sel_info.hslab->diminfo.opt[u].start >= offset[u]); - space->select.sel_info.hslab->diminfo.opt[u].start -= offset[u]; + /* Only perform operation if the offset is non-zero */ + if(non_zero_offset) { + /* Subtract the offset from the "regular" coordinates, if they exist */ + /* (No need to rebuild the dimension info yet -QAK) */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + for(u = 0; u < space->extent.rank; u++) { + HDassert(space->select.sel_info.hslab->diminfo.opt[u].start >= offset[u]); + space->select.sel_info.hslab->diminfo.opt[u].start -= offset[u]; - /* Adjust the low & high bounds */ - HDassert(space->select.sel_info.hslab->diminfo.low_bounds[u] >= offset[u]); - space->select.sel_info.hslab->diminfo.low_bounds[u] -= offset[u]; - space->select.sel_info.hslab->diminfo.high_bounds[u] -= offset[u]; - } /* end for */ - } /* end if */ + /* Adjust the low & high bounds */ + HDassert(space->select.sel_info.hslab->diminfo.low_bounds[u] >= offset[u]); + space->select.sel_info.hslab->diminfo.low_bounds[u] -= offset[u]; + space->select.sel_info.hslab->diminfo.high_bounds[u] -= offset[u]; + } /* end for */ + } /* end if */ - /* Subtract the offset from the span tree coordinates, if they exist */ - if(space->select.sel_info.hslab->span_lst) { - uint64_t op_gen; /* Operation generation value */ + /* Subtract the offset from the span tree coordinates, if they exist */ + if(space->select.sel_info.hslab->span_lst) { + uint64_t op_gen; /* Operation generation value */ - /* Acquire an operation generation value for this operation */ - op_gen = H5S__hyper_get_op_gen(); + /* Acquire an operation generation value for this operation */ + op_gen = H5S__hyper_get_op_gen(); - /* Perform adjustment */ - /* Always use op_info[0] since we own this op_info, so there can be no - * simultaneous operations */ - H5S__hyper_adjust_u_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, offset, 0, op_gen); + /* Perform adjustment */ + /* Always use op_info[0] since we own this op_info, so there can be no + * simultaneous operations */ + H5S__hyper_adjust_u_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, offset, 0, op_gen); + } /* end if */ } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED) 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() */ diff --git a/src/H5Sselect.c b/src/H5Sselect.c index ee7ad05..bf0441f 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -947,8 +947,6 @@ H5S_select_is_regular(const H5S_t *space) herr_t H5S_select_adjust_u(H5S_t *space, const hsize_t *offset) { - hbool_t non_zero_offset = FALSE; /* Whether any offset is non-zero */ - unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -957,16 +955,8 @@ H5S_select_adjust_u(H5S_t *space, const hsize_t *offset) HDassert(space); HDassert(offset); - /* 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 */ - - /* Only perform operation if the offset is non-zero */ - if(non_zero_offset) - ret_value = (*space->select.type->adjust_u)(space, offset); + /* Perform operation */ + ret_value = (*space->select.type->adjust_u)(space, offset); FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_select_adjust_u() */ @@ -996,8 +986,6 @@ H5S_select_adjust_u(H5S_t *space, const hsize_t *offset) herr_t H5S_select_adjust_s(H5S_t *space, const hssize_t *offset) { - hbool_t non_zero_offset = FALSE; /* Whether any offset is non-zero */ - unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -1006,16 +994,8 @@ H5S_select_adjust_s(H5S_t *space, const hssize_t *offset) HDassert(space); HDassert(offset); - /* 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 */ - - /* Only perform operation if the offset is non-zero */ - if(non_zero_offset) - ret_value = (*space->select.type->adjust_s)(space, offset); + /* Perform operation */ + ret_value = (*space->select.type->adjust_s)(space, offset); FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_select_adjust_s() */ -- cgit v0.12