cleaned up comments, changed loop to use ncindexlookup() instead of looping through the names
@@ -1553,14 +1553,11 @@ write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
{
replace_existing_var = NC_TRUE;
var->fill_val_changed = NC_FALSE;
- /* If the variable is going to be replaced,
- we need to flag any other attributes associated
- with the variable as 'dirty', or else
- *only* the fill value attribute will be copied over
- and the rest will be lost. See:
-
- * https://github.com/Unidata/netcdf-c/issues/239 */
-
+ /* If the variable is going to be replaced, we need to flag any
+ other attributes associated with the variable as 'dirty', or
+ else *only* the fill value attribute will be copied over and
+ the rest will be lost. See
+ https://github.com/Unidata/netcdf-c/issues/239 */
flag_atts_dirty(var->att);
}
@@ -1570,14 +1567,7 @@ write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
* this object exists in the HDF group. */
if (var->became_coord_var)
{
- NC_DIM_INFO_T *d1;
- int i;
-
- for (i = 0; i < ncindexsize(grp->dim); i++)
- {
- d1 = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
- assert(d1);
- if (!strcmp(d1->hdr.name, var->hdr.name))
+ if ((NC_DIM_INFO_T *)ncindexlookup(grp->dim, var->hdr.name))
{
nc_bool_t exists;
@@ -1585,22 +1575,16 @@ write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
return retval;
if (exists)
{
- /* Indicate that the variable already exists, and should be replaced */
+ /* Indicate that the variable already exists, and should
+ * be replaced. */
replace_existing_var = NC_TRUE;
flag_atts_dirty(var->att);
- break;
- }
}
}
}
/* Check dims if the variable will be replaced, so that the
- * dimensions will be de-attached and re-attached correctly. (Note:
- * There's a temptation to merge this loop over the dimensions with
- * the prior loop over dimensions, but that blurs the line over the
- * purpose of them, so they are currently separate. If performance
- * becomes an issue here, it would be possible to merge them. -QAK)
- */
+ * dimensions will be de-attached and re-attached correctly. */
if (replace_existing_var)
{
int i;
