simplify code using utils::strdup()

This commit is contained in:
Axel Kohlmeyer
2021-08-23 21:06:56 -04:00
parent 9a19a814e4
commit 1bd6e56369

View File

@ -264,58 +264,41 @@ int AtomKokkos::add_custom(const char *name, int flag, int cols)
if (flag == 0 && cols == 0) {
index = nivector;
nivector++;
ivname = (char **) memory->srealloc(ivname,nivector*sizeof(char *),
"atom:ivname");
int n = strlen(name) + 1;
ivname[index] = new char[n];
strcpy(ivname[index],name);
ivector = (int **) memory->srealloc(ivector,nivector*sizeof(int *),
"atom:ivector");
memory->create(ivector[index],nmax,"atom:ivector");
ivname = (char **) memory->srealloc(ivname, nivector * sizeof(char *), "atom:ivname");
ivname[index] = utils::strdup(name);
ivector = (int **) memory->srealloc(ivector, nivector * sizeof(int *), "atom:ivector");
memory->create(ivector[index], nmax, "atom:ivector");
} else if (flag == 1 && cols == 0) {
index = ndvector;
ndvector++;
dvname = (char **) memory->srealloc(dvname,ndvector*sizeof(char *),
"atom:dvname");
int n = strlen(name) + 1;
dvname[index] = new char[n];
strcpy(dvname[index],name);
dvector = (double **) memory->srealloc(dvector,ndvector*sizeof(double *),
"atom:dvector");
this->sync(Device,DVECTOR_MASK);
memoryKK->grow_kokkos(k_dvector,dvector,ndvector,nmax,
"atom:dvector");
this->modified(Device,DVECTOR_MASK);
dvname = (char **) memory->srealloc(dvname, ndvector * sizeof(char *), "atom:dvname");
dvname[index] = utils::strdup(name);
dvector = (double **) memory->srealloc(dvector, ndvector * sizeof(double *), "atom:dvector");
this->sync(Device, DVECTOR_MASK);
memoryKK->grow_kokkos(k_dvector, dvector, ndvector, nmax, "atom:dvector");
this->modified(Device, DVECTOR_MASK);
} else if (flag == 0 && cols) {
index = niarray;
niarray++;
ianame = (char **) memory->srealloc(ianame,niarray*sizeof(char *),
"atom:ianame");
int n = strlen(name) + 1;
ianame[index] = new char[n];
strcpy(ianame[index],name);
iarray = (int ***) memory->srealloc(iarray,niarray*sizeof(int **),
"atom:iarray");
memory->create(iarray[index],nmax,cols,"atom:iarray");
ianame = (char **) memory->srealloc(ianame, niarray * sizeof(char *), "atom:ianame");
ianame[index] = utils::strdup(name);
iarray = (int ***) memory->srealloc(iarray, niarray * sizeof(int **), "atom:iarray");
memory->create(iarray[index], nmax, cols, "atom:iarray");
icols = (int *) memory->srealloc(icols,niarray*sizeof(int),"atom:icols");
icols = (int *) memory->srealloc(icols, niarray * sizeof(int), "atom:icols");
icols[index] = cols;
} else if (flag == 1 && cols) {
index = ndarray;
ndarray++;
daname = (char **) memory->srealloc(daname,ndarray*sizeof(char *),
"atom:daname");
int n = strlen(name) + 1;
daname[index] = new char[n];
strcpy(daname[index],name);
darray = (double ***) memory->srealloc(darray,ndarray*sizeof(double **),
"atom:darray");
memory->create(darray[index],nmax,cols,"atom:darray");
daname = (char **) memory->srealloc(daname, ndarray * sizeof(char *), "atom:daname");
daname[index] = utils::strdup(name);
darray = (double ***) memory->srealloc(darray, ndarray * sizeof(double **), "atom:darray");
memory->create(darray[index], nmax, cols, "atom:darray");
dcols = (int *) memory->srealloc(dcols,ndarray*sizeof(int),"atom:dcols");
dcols = (int *) memory->srealloc(dcols, ndarray * sizeof(int), "atom:dcols");
dcols[index] = cols;
}
@ -333,24 +316,24 @@ void AtomKokkos::remove_custom(int index, int flag, int cols)
if (flag == 0 && cols == 0) {
memory->destroy(ivector[index]);
ivector[index] = NULL;
delete [] ivname[index];
delete[] ivname[index];
ivname[index] = NULL;
} else if (flag == 1 && cols == 0) {
dvector[index] = NULL;
delete [] dvname[index];
delete[] dvname[index];
dvname[index] = NULL;
} else if (flag == 0 && cols) {
memory->destroy(iarray[index]);
iarray[index] = NULL;
delete [] ianame[index];
delete[] ianame[index];
ianame[index] = NULL;
} else if (flag == 1 && cols) {
memory->destroy(darray[index]);
darray[index] = NULL;
delete [] daname[index];
delete[] daname[index];
daname[index] = NULL;
}
}