diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-05-31 20:01:29 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-05-31 20:01:29 (GMT) |
commit | b4ac48552d74bcd4ad465d61d2fa294420f2525d (patch) | |
tree | 7925b715974b10b69bc2662c2045eb8281f1b726 /src/H5Oefl.c | |
parent | fbe777b67a3b859d6688111a43f24444cff7d335 (diff) | |
download | hdf5-b4ac48552d74bcd4ad465d61d2fa294420f2525d.zip hdf5-b4ac48552d74bcd4ad465d61d2fa294420f2525d.tar.gz hdf5-b4ac48552d74bcd4ad465d61d2fa294420f2525d.tar.bz2 |
[svn-r8601] Purpose:
Code optimization & cleanup
Description:
Don't recompute the internal index value for looking up the chunk in the
hash table, just use the value already computed from iterating through the
chunks.
Also, back-port some of the various cleanups to the source code from the
development branch, to make diffing the code easier.
Platforms tested:
Solaris 2.7 (arabica)
FreeBSD 4.9 (sleipnir) w/parallel
Diffstat (limited to 'src/H5Oefl.c')
-rw-r--r-- | src/H5Oefl.c | 114 |
1 files changed, 58 insertions, 56 deletions
diff --git a/src/H5Oefl.c b/src/H5Oefl.c index 061ba01..e77a691 100644 --- a/src/H5Oefl.c +++ b/src/H5Oefl.c @@ -90,8 +90,9 @@ static void * H5O_efl_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p, H5O_shared_t UNUSED *sh) { H5O_efl_t *mesg = NULL; - int i, version; + int version; const char *s = NULL; + size_t u; /* Local index variable */ void *ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5O_efl_decode, NULL); @@ -130,19 +131,19 @@ H5O_efl_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p, H5O_shared_t UNUSED *s mesg->slot = H5MM_calloc(mesg->nalloc*sizeof(H5O_efl_entry_t)); if (NULL==mesg->slot) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); - for (i=0; i<mesg->nused; i++) { + for (u=0; u<mesg->nused; u++) { /* Name */ - H5F_DECODE_LENGTH (f, p, mesg->slot[i].name_offset); - s = H5HL_peek(f, dxpl_id, mesg->heap_addr, mesg->slot[i].name_offset); + H5F_DECODE_LENGTH (f, p, mesg->slot[u].name_offset); + s = H5HL_peek(f, dxpl_id, mesg->heap_addr, mesg->slot[u].name_offset); assert (s && *s); - mesg->slot[i].name = H5MM_xstrdup (s); + mesg->slot[u].name = H5MM_xstrdup (s); /* File offset */ - H5F_DECODE_LENGTH (f, p, mesg->slot[i].offset); + H5F_DECODE_LENGTH (f, p, mesg->slot[u].offset); /* Size */ - H5F_DECODE_LENGTH (f, p, mesg->slot[i].size); - assert (mesg->slot[i].size>0); + H5F_DECODE_LENGTH (f, p, mesg->slot[u].size); + assert (mesg->slot[u].size>0); } /* Set return value */ @@ -182,7 +183,7 @@ static herr_t H5O_efl_encode(H5F_t *f, uint8_t *p, const void *_mesg) { const H5O_efl_t *mesg = (const H5O_efl_t *)_mesg; - int i; + size_t u; /* Local index variable */ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5O_efl_encode, FAIL); @@ -211,15 +212,15 @@ H5O_efl_encode(H5F_t *f, uint8_t *p, const void *_mesg) H5F_addr_encode(f, &p, mesg->heap_addr); /* Encode file list */ - for (i=0; i<mesg->nused; i++) { + for (u=0; u<mesg->nused; u++) { /* * The name should have been added to the heap when the dataset was * created. */ - assert(mesg->slot[i].name_offset); - H5F_ENCODE_LENGTH (f, p, mesg->slot[i].name_offset); - H5F_ENCODE_LENGTH (f, p, mesg->slot[i].offset); - H5F_ENCODE_LENGTH (f, p, mesg->slot[i].size); + assert(mesg->slot[u].name_offset); + H5F_ENCODE_LENGTH (f, p, mesg->slot[u].name_offset); + H5F_ENCODE_LENGTH (f, p, mesg->slot[u].offset); + H5F_ENCODE_LENGTH (f, p, mesg->slot[u].size); } done: @@ -249,7 +250,7 @@ H5O_efl_copy(const void *_mesg, void *_dest) { const H5O_efl_t *mesg = (const H5O_efl_t *) _mesg; H5O_efl_t *dest = (H5O_efl_t *) _dest; - int i; + size_t u; /* Local index variable */ void *ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5O_efl_copy, NULL); @@ -271,9 +272,9 @@ H5O_efl_copy(const void *_mesg, void *_dest) dest->nalloc = mesg->nalloc; dest->nused = mesg->nused; - for (i = 0; i < mesg->nused; i++) { - dest->slot[i] = mesg->slot[i]; - dest->slot[i].name = H5MM_xstrdup (mesg->slot[i].name); + for (u = 0; u < mesg->nused; u++) { + dest->slot[u] = mesg->slot[u]; + dest->slot[u].name = H5MM_xstrdup (mesg->slot[u].name); } /* Set return value */ @@ -347,7 +348,7 @@ static herr_t H5O_efl_reset(void *_mesg) { H5O_efl_t *mesg = (H5O_efl_t *) _mesg; - int i; + size_t u; /* Local index variable */ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5O_efl_reset, FAIL); @@ -356,8 +357,8 @@ H5O_efl_reset(void *_mesg) assert(mesg); /* reset */ - for (i=0; i<mesg->nused; i++) - mesg->slot[i].name = H5MM_xfree (mesg->slot[i].name); + for (u=0; u<mesg->nused; u++) + mesg->slot[u].name = H5MM_xfree (mesg->slot[u].name); mesg->heap_addr = HADDR_UNDEF; mesg->nused = mesg->nalloc = 0; if(mesg->slot) @@ -388,7 +389,6 @@ done: hsize_t H5O_efl_total_size (H5O_efl_t *efl) { - int i; hsize_t ret_value = 0, tmp; FUNC_ENTER_NOAPI(H5O_efl_total_size, 0); @@ -397,8 +397,10 @@ H5O_efl_total_size (H5O_efl_t *efl) H5O_EFL_UNLIMITED==efl->slot[efl->nused-1].size) { ret_value = H5O_EFL_UNLIMITED; } else { - for (i=0; i<efl->nused; i++, ret_value=tmp) { - tmp = ret_value + efl->slot[i].size; + size_t u; /* Local index variable */ + + for (u=0; u<efl->nused; u++, ret_value=tmp) { + tmp = ret_value + efl->slot[u].size; if (tmp<=ret_value) HGOTO_ERROR (H5E_EFL, H5E_OVERFLOW, 0, "total external storage size overflowed"); } @@ -430,7 +432,7 @@ done: static herr_t H5O_efl_read (const H5O_efl_t *efl, haddr_t addr, size_t size, uint8_t *buf) { - int i, fd=-1; + int fd=-1; size_t to_read; #ifndef NDEBUG hsize_t tempto_read; @@ -438,6 +440,7 @@ H5O_efl_read (const H5O_efl_t *efl, haddr_t addr, size_t size, uint8_t *buf) hsize_t skip=0; haddr_t cur; ssize_t n; + size_t u; /* Local index variable */ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5O_efl_read, FAIL); @@ -449,31 +452,30 @@ H5O_efl_read (const H5O_efl_t *efl, haddr_t addr, size_t size, uint8_t *buf) assert (buf || 0==size); /* Find the first efl member from which to read */ - for (i=0, cur=0; i<efl->nused; i++) { - if (H5O_EFL_UNLIMITED==efl->slot[i].size || - addr < cur+efl->slot[i].size) { + for (u=0, cur=0; u<efl->nused; u++) { + if (H5O_EFL_UNLIMITED==efl->slot[u].size || addr < cur+efl->slot[u].size) { skip = addr - cur; break; } - cur += efl->slot[i].size; + cur += efl->slot[u].size; } /* Read the data */ while (size) { - if (i>=efl->nused) + if (u>=efl->nused) HGOTO_ERROR (H5E_EFL, H5E_OVERFLOW, FAIL, "read past logical end of file"); - if (H5F_OVERFLOW_HSIZET2OFFT (efl->slot[i].offset+skip)) + if (H5F_OVERFLOW_HSIZET2OFFT (efl->slot[u].offset+skip)) HGOTO_ERROR (H5E_EFL, H5E_OVERFLOW, FAIL, "external file address overflowed"); - if ((fd=HDopen (efl->slot[i].name, O_RDONLY, 0))<0) + if ((fd=HDopen (efl->slot[u].name, O_RDONLY, 0))<0) HGOTO_ERROR (H5E_EFL, H5E_CANTOPENFILE, FAIL, "unable to open external raw data file"); - if (HDlseek (fd, (off_t)(efl->slot[i].offset+skip), SEEK_SET)<0) + if (HDlseek (fd, (off_t)(efl->slot[u].offset+skip), SEEK_SET)<0) HGOTO_ERROR (H5E_EFL, H5E_SEEKERROR, FAIL, "unable to seek in external raw data file"); #ifndef NDEBUG - tempto_read = MIN(efl->slot[i].size-skip,(hsize_t)size); + tempto_read = MIN(efl->slot[u].size-skip,(hsize_t)size); H5_CHECK_OVERFLOW(tempto_read,hsize_t,size_t); to_read = (size_t)tempto_read; #else /* NDEBUG */ - to_read = MIN((size_t)(efl->slot[i].size-skip), size); + to_read = MIN((size_t)(efl->slot[u].size-skip), size); #endif /* NDEBUG */ if ((n=HDread (fd, buf, to_read))<0) { HGOTO_ERROR (H5E_EFL, H5E_READERROR, FAIL, "read error in external raw data file"); @@ -485,7 +487,7 @@ H5O_efl_read (const H5O_efl_t *efl, haddr_t addr, size_t size, uint8_t *buf) size -= to_read; buf += to_read; skip = 0; - i++; + u++; } done: @@ -517,13 +519,14 @@ done: static herr_t H5O_efl_write (const H5O_efl_t *efl, haddr_t addr, size_t size, const uint8_t *buf) { - int i, fd=-1; + int fd=-1; size_t to_write; #ifndef NDEBUG hsize_t tempto_write; #endif /* NDEBUG */ haddr_t cur; hsize_t skip=0; + size_t u; /* Local index variable */ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5O_efl_write, FAIL); @@ -535,36 +538,35 @@ H5O_efl_write (const H5O_efl_t *efl, haddr_t addr, size_t size, const uint8_t *b assert (buf || 0==size); /* Find the first efl member in which to write */ - for (i=0, cur=0; i<efl->nused; i++) { - if (H5O_EFL_UNLIMITED==efl->slot[i].size || - addr < cur+efl->slot[i].size) { + for (u=0, cur=0; u<efl->nused; u++) { + if (H5O_EFL_UNLIMITED==efl->slot[u].size || addr < cur+efl->slot[u].size) { skip = addr - cur; break; } - cur += efl->slot[i].size; + cur += efl->slot[u].size; } /* Write the data */ while (size) { - if (i>=efl->nused) + if (u>=efl->nused) HGOTO_ERROR (H5E_EFL, H5E_OVERFLOW, FAIL, "write past logical end of file"); - if (H5F_OVERFLOW_HSIZET2OFFT (efl->slot[i].offset+skip)) + if (H5F_OVERFLOW_HSIZET2OFFT (efl->slot[u].offset+skip)) HGOTO_ERROR (H5E_EFL, H5E_OVERFLOW, FAIL, "external file address overflowed"); - if ((fd=HDopen (efl->slot[i].name, O_CREAT|O_RDWR, 0666))<0) { - if (HDaccess (efl->slot[i].name, F_OK)<0) { + if ((fd=HDopen (efl->slot[u].name, O_CREAT|O_RDWR, 0666))<0) { + if (HDaccess (efl->slot[u].name, F_OK)<0) { HGOTO_ERROR (H5E_EFL, H5E_CANTOPENFILE, FAIL, "external raw data file does not exist"); } else { HGOTO_ERROR (H5E_EFL, H5E_CANTOPENFILE, FAIL, "unable to open external raw data file"); } } - if (HDlseek (fd, (off_t)(efl->slot[i].offset+skip), SEEK_SET)<0) + if (HDlseek (fd, (off_t)(efl->slot[u].offset+skip), SEEK_SET)<0) HGOTO_ERROR (H5E_EFL, H5E_SEEKERROR, FAIL, "unable to seek in external raw data file"); #ifndef NDEBUG - tempto_write = MIN(efl->slot[i].size-skip,(hsize_t)size); + tempto_write = MIN(efl->slot[u].size-skip,(hsize_t)size); H5_CHECK_OVERFLOW(tempto_write,hsize_t,size_t); to_write = (size_t)tempto_write; #else /* NDEBUG */ - to_write = MIN((size_t)(efl->slot[i].size-skip), size); + to_write = MIN((size_t)(efl->slot[u].size-skip), size); #endif /* NDEBUG */ if ((size_t)HDwrite (fd, buf, to_write)!=to_write) HGOTO_ERROR (H5E_EFL, H5E_READERROR, FAIL, "write error in external raw data file"); @@ -573,7 +575,7 @@ H5O_efl_write (const H5O_efl_t *efl, haddr_t addr, size_t size, const uint8_t *b size -= to_write; buf += to_write; skip = 0; - i++; + u++; } done: @@ -762,7 +764,7 @@ H5O_efl_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *_mesg, FILE * s { const H5O_efl_t *mesg = (const H5O_efl_t *) _mesg; char buf[64]; - int i; + size_t u; herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5O_efl_debug, FAIL); @@ -781,25 +783,25 @@ H5O_efl_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *_mesg, FILE * s "Slots used/allocated:", mesg->nused, mesg->nalloc); - for (i = 0; i < mesg->nused; i++) { - sprintf (buf, "File %d", i); + for (u = 0; u < mesg->nused; u++) { + sprintf (buf, "File %u", (unsigned)u); HDfprintf (stream, "%*s%s:\n", indent, "", buf); HDfprintf(stream, "%*s%-*s \"%s\"\n", indent+3, "", MAX (fwidth-3, 0), "Name:", - mesg->slot[i].name); + mesg->slot[u].name); HDfprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0), "Name offset:", - (unsigned long)(mesg->slot[i].name_offset)); + (unsigned long)(mesg->slot[u].name_offset)); HDfprintf (stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0), "Offset of data in file:", - (unsigned long)(mesg->slot[i].offset)); + (unsigned long)(mesg->slot[u].offset)); HDfprintf (stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0), "Bytes reserved for data:", - (unsigned long)(mesg->slot[i].size)); + (unsigned long)(mesg->slot[u].size)); } done: |