diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-06-13 20:12:55 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-06-13 20:12:55 (GMT) |
commit | 6ed61e5dda6a877b955aab386379b189346bf74c (patch) | |
tree | 9413d3b78efcd467f21a84a5f710669ab18ca578 /src/H5Oattr.c | |
parent | 737f79b5da933853fde9a194d3fe5c4bd820261b (diff) | |
download | hdf5-6ed61e5dda6a877b955aab386379b189346bf74c.zip hdf5-6ed61e5dda6a877b955aab386379b189346bf74c.tar.gz hdf5-6ed61e5dda6a877b955aab386379b189346bf74c.tar.bz2 |
[svn-r8676] Purpose:
Code optimization
Description:
Using existing dataspace extent copying routine instead of duplicating the
code (more slowly).
Also, back-port improvements to the dataspace message reading which clean
up the clean and centralize operations.
Platforms tested:
Solaris 2.7 (arabica)
FreeBSD 4.10 (sleipnir) w/parallel
Too minor to require h5committest
Diffstat (limited to 'src/H5Oattr.c')
-rw-r--r-- | src/H5Oattr.c | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/src/H5Oattr.c b/src/H5Oattr.c index e1528ef..f454b74 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -74,8 +74,8 @@ static int interface_initialize_g = 0; /* Declare external the free list for H5S_t's */ H5FL_EXTERN(H5S_t); -/* Declare external the free list for H5S_simple_t's */ -H5FL_EXTERN(H5S_simple_t); +/* Declare external the free list for H5S_extent_t's */ +H5FL_EXTERN(H5S_extent_t); /*-------------------------------------------------------------------------- NAME @@ -101,12 +101,16 @@ H5FL_EXTERN(H5S_simple_t); * * Robb Matzke, 20 Jul 1998 * Added a version number at the beginning. + * + * Raymond Lu, 8 April 2004 + * Changed Dataspace operation on H5S_simple_t to H5S_extent_t. + * --------------------------------------------------------------------------*/ static void * H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p, H5O_shared_t UNUSED *sh) { H5A_t *attr = NULL; - H5S_simple_t *simple; /*simple dimensionality information */ + H5S_extent_t *extent; /*extent dimensionality information */ size_t name_len; /*attribute name length */ int version; /*message version number*/ unsigned flags=0; /* Attribute flags */ @@ -176,30 +180,16 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p, H5O_shared_t UNUSED * /* decode the attribute dataspace */ if (NULL==(attr->ds = H5FL_CALLOC(H5S_t))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - if((simple=(H5O_SDSPACE->decode)(f,dxpl_id,p,NULL))!=NULL) { - hsize_t nelem; /* Number of elements in extent */ - unsigned u; /* Local index variable */ - - /* Set the dataspace type to be simple or scalar as appropriate */ - if(simple->rank>0) - attr->ds->extent.type = H5S_SIMPLE; - else - attr->ds->extent.type = H5S_SCALAR; - - /* Copy the extent information */ - HDmemcpy(&(attr->ds->extent.u.simple),simple, sizeof(H5S_simple_t)); - - /* Release temporary extent information */ - H5FL_FREE(H5S_simple_t,simple); - - /* Compute the number of elements in the extent */ - for(u=0, nelem=1; u<attr->ds->extent.u.simple.rank; u++) - nelem*=attr->ds->extent.u.simple.size[u]; - attr->ds->extent.nelem = nelem; - } else { + + if((extent=(H5O_SDSPACE->decode)(f,dxpl_id,p,NULL))==NULL) HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL, "can't decode attribute dataspace"); - } + /* Copy the extent information */ + HDmemcpy(&(attr->ds->extent),extent, sizeof(H5S_extent_t)); + + /* Release temporary extent information */ + H5FL_FREE(H5S_extent_t,extent); + /* Default to entire dataspace being selected */ if(H5S_select_all(attr->ds,0)<0) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection"); @@ -213,20 +203,15 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p, H5O_shared_t UNUSED * H5_ASSIGN_OVERFLOW(attr->data_size,H5S_GET_EXTENT_NPOINTS(attr->ds)*H5T_get_size(attr->dt),hsize_t,size_t); /* Go get the data */ - if (NULL==(attr->data = H5MM_malloc(attr->data_size))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - HDmemcpy(attr->data,p,attr->data_size); + if(attr->data_size) { + if (NULL==(attr->data = H5MM_malloc(attr->data_size))) + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); + HDmemcpy(attr->data,p,attr->data_size); + } /* Indicate that the fill values aren't to be written out */ attr->initialized=1; -#ifdef LOTSLATER - if (hobj) { - attr->sh_heap = *hobj; - attr->sh_file = f; - } -#endif - /* Set return value */ ret_value=attr; @@ -257,6 +242,11 @@ done: * * Robb Matzke, 20 Jul 1998 * Added a version number at the beginning. + * + * Raymond Lu, 8 April 2004 + * For data space, changed the operation on H5S_simple_t to + * H5S_extent_t + * --------------------------------------------------------------------------*/ static herr_t H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) @@ -344,7 +334,7 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg) p += attr->dt_size; /* encode the attribute dataspace */ - if((H5O_SDSPACE->encode)(f,p,&(attr->ds->extent.u.simple))<0) + if((H5O_SDSPACE->encode)(f,p,&(attr->ds->extent))<0) HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode attribute dataspace"); if(version < H5O_ATTR_VERSION_NEW) { HDmemset(p+attr->ds_size, 0, H5O_ALIGN(attr->ds_size)-attr->ds_size); |