Commit d1dd4524 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Use serialization table to replace repeated code with loop.

parent cce119cf
......@@ -2769,6 +2769,10 @@ static void gridComplete(grid_t *grid)
}
#define GRID_STR_SERIALIZE(gridP) { gridP->xname, gridP->yname, \
gridP->xlongname, gridP->ylongname, \
gridP->xunits, gridP->yunits }
int gridGenerate(const grid_t *grid)
{
int gridID = gridCreate(grid->type, grid->size);
......@@ -2824,18 +2828,11 @@ int gridGenerate(const grid_t *grid)
gridptr->ni = grid->ni;
gridptr->ni2 = grid->ni2;
gridptr->ni3 = grid->ni3;
if ( grid->xname[0] )
memcpy(gridptr->xname, grid->xname, CDI_MAX_NAME);
if ( grid->yname[0] )
memcpy(gridptr->yname, grid->yname, CDI_MAX_NAME);
if ( grid->xlongname[0] )
memcpy(gridptr->xlongname, grid->xlongname, CDI_MAX_NAME);
if ( grid->ylongname[0] )
memcpy(gridptr->ylongname, grid->ylongname, CDI_MAX_NAME);
if ( grid->xunits[0] )
memcpy(gridptr->xunits, grid->xunits, CDI_MAX_NAME);
if ( grid->yunits[0] )
memcpy(gridptr->yunits, grid->yunits, CDI_MAX_NAME);
const char *grid_str_tab[] = GRID_STR_SERIALIZE(grid);
char *gridptr_str_tab[] = GRID_STR_SERIALIZE(gridptr);
for (size_t i = 0; i < sizeof (grid_str_tab) / sizeof (grid_str_tab[0]); ++i)
if ( grid_str_tab[i][0] )
memcpy(gridptr_str_tab[i], grid_str_tab[i], CDI_MAX_NAME);
gridComplete(gridptr);
return (gridID);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment