diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-09-22 20:01:30 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-09-22 20:01:30 (GMT) |
commit | e3f4d1c653da894b2bcade837ff32f7c9384bfa4 (patch) | |
tree | 2f9d27ed0ecf74884e93301479808f479a10c208 /src/H5G.c | |
parent | c28a37e44ba70119d073d8e452dcbe25e2586423 (diff) | |
download | hdf5-e3f4d1c653da894b2bcade837ff32f7c9384bfa4.zip hdf5-e3f4d1c653da894b2bcade837ff32f7c9384bfa4.tar.gz hdf5-e3f4d1c653da894b2bcade837ff32f7c9384bfa4.tar.bz2 |
[svn-r9311] Purpose:
Code optimization
Description:
Avoid performing a check on the number of objects in a group (which
currently involves iterating over all entries in the group's B-tree) before
calling H5G_get_obj<foo>_by_idx. Instead, just have H5G_get_obj<foo>_by_idx()
notice when you've walked off the end and return fail then.
Platforms tested:
FreeBSD 4.10 (sleipnir)
h5committest
Diffstat (limited to 'src/H5G.c')
-rw-r--r-- | src/H5G.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -513,7 +513,9 @@ ssize_t H5Gget_objname_by_idx(hid_t loc_id, hsize_t idx, char *name, size_t size) { H5G_entry_t *loc = NULL; /* Pointer to symbol table entry */ +#ifdef OLD_WAY hsize_t num_objs; +#endif /* OLD_WAY */ ssize_t ret_value = FAIL; FUNC_ENTER_API(H5Gget_objname_by_idx, FAIL); @@ -525,10 +527,17 @@ H5Gget_objname_by_idx(hid_t loc_id, hsize_t idx, char *name, size_t size) if(H5G_get_type(loc,H5AC_ind_dxpl_id)!=H5G_GROUP) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a group"); +#ifdef OLD_WAY +/* Don't check for the number of objects in the group currently, because this + * has to iterate through the group in order to find out the information. + * We might as well just iterate through all the group entries and error out + * if we didn't find the index we are looking for. -QAK + */ if (H5G_get_num_objs(loc, &num_objs, H5AC_ind_dxpl_id)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "unable to retrieve number of members"); if(idx >= num_objs) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "index out of bound"); +#endif /* OLD_WAY */ /*call private function*/ ret_value = H5G_get_objname_by_idx(loc, idx, name, size, H5AC_ind_dxpl_id); @@ -560,7 +569,9 @@ int H5Gget_objtype_by_idx(hid_t loc_id, hsize_t idx) { H5G_entry_t *loc = NULL; /* Pointer to symbol table entry */ +#ifdef OLD_WAY hsize_t num_objs; +#endif /* OLD_WAY */ int ret_value = H5G_UNKNOWN; FUNC_ENTER_API(H5Gget_objtype_by_idx, FAIL); @@ -572,10 +583,17 @@ H5Gget_objtype_by_idx(hid_t loc_id, hsize_t idx) if(H5G_get_type(loc,H5AC_ind_dxpl_id)!=H5G_GROUP) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a group"); +#ifdef OLD_WAY +/* Don't check for the number of objects in the group currently, because this + * has to iterate through the group in order to find out the information. + * We might as well just iterate through all the group entries and error out + * if we didn't find the index we are looking for. -QAK + */ if (H5G_get_num_objs(loc, &num_objs, H5AC_ind_dxpl_id)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "unable to retrieve number of members"); if(idx >= num_objs) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "index out of bound"); +#endif /* OLD_WAY */ /*call private function*/ ret_value = H5G_get_objtype_by_idx(loc, idx, H5AC_ind_dxpl_id); @@ -590,7 +608,9 @@ H5G_obj_t H5Gget_objtype_by_idx(hid_t loc_id, hsize_t idx) { H5G_entry_t *loc = NULL; /* Pointer to symbol table entry */ +#ifdef OLD_WAY hsize_t num_objs; +#endif /* OLD_WAY */ H5G_obj_t ret_value; FUNC_ENTER_API(H5Gget_objtype_by_idx, H5G_UNKNOWN); @@ -602,10 +622,17 @@ H5Gget_objtype_by_idx(hid_t loc_id, hsize_t idx) if(H5G_get_type(loc,H5AC_ind_dxpl_id)!=H5G_GROUP) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, H5G_UNKNOWN, "not a group"); +#ifdef OLD_WAY +/* Don't check for the number of objects in the group currently, because this + * has to iterate through the group in order to find out the information. + * We might as well just iterate through all the group entries and error out + * if we didn't find the index we are looking for. -QAK + */ if (H5G_get_num_objs(loc, &num_objs, H5AC_ind_dxpl_id)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5G_UNKNOWN, "unable to retrieve number of members"); if(idx >= num_objs) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5G_UNKNOWN, "index out of bound"); +#endif /* OLD_WAY */ /*call private function*/ ret_value = (H5G_obj_t)H5G_get_objtype_by_idx(loc, idx, H5AC_ind_dxpl_id); @@ -2737,6 +2764,10 @@ H5G_get_objname_by_idx(H5G_entry_t *loc, hsize_t idx, char* name, size_t size, h H5G_node_name, loc->cache.stab.btree_addr, &udata))<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "iteration operator failed"); + /* If we don't know the name now, we almost certainly went out of bounds */ + if(udata.name==NULL) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "index out of bound"); + /* Get the length of the name */ ret_value = (ssize_t)HDstrlen(udata.name); @@ -2788,12 +2819,17 @@ H5G_get_objtype_by_idx(H5G_entry_t *loc, hsize_t idx, hid_t dxpl_id) udata.idx = idx; udata.num_objs = 0; udata.ent = loc; + udata.type = H5G_UNKNOWN; /* Iterate over the group members */ if (H5B_iterate (loc->file, dxpl_id, H5B_SNODE, H5G_node_type, loc->cache.stab.btree_addr, &udata)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "iteration operator failed"); + /* If we don't know the type now, we almost certainly went out of bounds */ + if(udata.type==H5G_UNKNOWN) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5G_UNKNOWN, "index out of bound"); + ret_value = udata.type; done: |