diff options
author | Neil Fortner <nfortne2@hdfgroup.org> | 2021-01-20 00:42:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-20 00:42:14 (GMT) |
commit | a5ffedb8c6c0654ec78c2872ed912610d2e86d64 (patch) | |
tree | 9f91fd136154466824447c3672ad28bb510654e9 /src/H5Spoint.c | |
parent | 9578160cefb794fc2fde7c8040c945df498b9e4a (diff) | |
download | hdf5-a5ffedb8c6c0654ec78c2872ed912610d2e86d64.zip hdf5-a5ffedb8c6c0654ec78c2872ed912610d2e86d64.tar.gz hdf5-a5ffedb8c6c0654ec78c2872ed912610d2e86d64.tar.bz2 |
Improve performance of multiple calls to H5Sget_select_elem_pointlist (#270)
* Cache the pointer to the next point to process after the last call to
H5S__get_select_elem_pointlist. This allows the normal process of
iterating over the points in batches to be much more efficient, as the
library does not need to traverse the entirety of the preceding points
every time the funciton is re-entered.
* Update RELEASE.txt for point selection iteration performance fix.
Diffstat (limited to 'src/H5Spoint.c')
-rw-r--r-- | src/H5Spoint.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/H5Spoint.c b/src/H5Spoint.c index c58e7a7..6cb5d9b 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -843,6 +843,10 @@ H5S__copy_pnt_list(const H5S_pnt_list_t *src, unsigned rank) H5MM_memcpy(dst->high_bounds, src->high_bounds, (rank * sizeof(hsize_t))); H5MM_memcpy(dst->low_bounds, src->low_bounds, (rank * sizeof(hsize_t))); + /* Clear cached iteration point */ + dst->last_idx = 0; + dst->last_idx_pnt = NULL; + /* Set return value */ ret_value = dst; @@ -1511,6 +1515,7 @@ done: static herr_t H5S__get_select_elem_pointlist(const H5S_t *space, hsize_t startpoint, hsize_t numpoints, hsize_t *buf) { + const hsize_t endpoint = startpoint + numpoints; /* Index of last point in iteration */ H5S_pnt_node_t *node; /* Point node */ unsigned rank; /* Dataspace rank */ @@ -1522,14 +1527,20 @@ H5S__get_select_elem_pointlist(const H5S_t *space, hsize_t startpoint, hsize_t n /* Get the dataspace extent rank */ rank = space->extent.rank; - /* Get the head of the point list */ - node = space->select.sel_info.pnt_lst->head; + /* Check for cached point at the correct index */ + if(space->select.sel_info.pnt_lst->last_idx_pnt + && startpoint == space->select.sel_info.pnt_lst->last_idx) + node = space->select.sel_info.pnt_lst->last_idx_pnt; + else { + /* Get the head of the point list */ + node = space->select.sel_info.pnt_lst->head; - /* Iterate to the first point to return */ - while (node != NULL && startpoint > 0) { - startpoint--; - node = node->next; - } /* end while */ + /* Iterate to the first point to return */ + while (node != NULL && startpoint > 0) { + startpoint--; + node = node->next; + } /* end while */ + } /* end else */ /* Iterate through the node, copying each point's information */ while (node != NULL && numpoints > 0) { @@ -1539,6 +1550,10 @@ H5S__get_select_elem_pointlist(const H5S_t *space, hsize_t startpoint, hsize_t n node = node->next; } /* end while */ + /* Cached next point in iteration */ + space->select.sel_info.pnt_lst->last_idx = endpoint; + space->select.sel_info.pnt_lst->last_idx_pnt = node; + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S__get_select_elem_pointlist() */ @@ -2331,6 +2346,10 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of } /* end for */ } /* end else */ + /* Clear cached iteration point */ + new_space->select.sel_info.pnt_lst->last_idx = 0; + new_space->select.sel_info.pnt_lst->last_idx_pnt = NULL; + /* Number of elements selected will be the same */ new_space->select.num_elem = base_space->select.num_elem; |