From e902ebd34da01e0f8186cc49c483d4973ac539af Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 12 Apr 2015 18:11:33 +0200 Subject: [PATCH] devices/asrc, rewrite #2/10, simplify incremental memory allocation --- src/spicelib/devices/asrc/asrcset.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/spicelib/devices/asrc/asrcset.c b/src/spicelib/devices/asrc/asrcset.c index 460844d50..55817c04b 100644 --- a/src/spicelib/devices/asrc/asrcset.c +++ b/src/spicelib/devices/asrc/asrcset.c @@ -20,7 +20,6 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) ASRCinstance *here; ASRCmodel *model = (ASRCmodel*) inModel; int error, i, j; - int v_first; CKTnode *tmp; NG_IGNORE(states); @@ -37,7 +36,6 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) here->ASRCposptr = NULL; j = 0; /* strchr of the array holding ptrs to SMP */ - v_first = 1; if (here->ASRCtype == ASRC_VOLTAGE) if (here->ASRCbranch == 0) { @@ -70,7 +68,7 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) return(E_UNSUPP); } - here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 5); + here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 4); TSTALLOC(ASRCposptr[j++], ASRCposNode, ASRCbranch); TSTALLOC(ASRCposptr[j++], ASRCnegNode, ASRCbranch); @@ -89,13 +87,8 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) } if (here->ASRCtype == ASRC_VOLTAGE) { /* CCVS */ - if (v_first) { - TSTALLOC(ASRCposptr[j++], ASRCbranch, ASRCcont_br); - v_first = 0; - } else { - here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 1); - TSTALLOC(ASRCposptr[j++], ASRCbranch, ASRCcont_br); - } + here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 1); + TSTALLOC(ASRCposptr[j++], ASRCbranch, ASRCcont_br); } else if (here->ASRCtype == ASRC_CURRENT) { /* CCCS */ here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 2); @@ -108,13 +101,8 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) case IF_NODE: if (here->ASRCtype == ASRC_VOLTAGE) { /* VCVS */ - if (v_first) { - MY_TSTALLOC(ASRCposptr[j++], ASRCbranch, here->ASRCtree->vars[i].nValue); - v_first = 0; - } else { - here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 1); - MY_TSTALLOC(ASRCposptr[j++], ASRCbranch, here->ASRCtree->vars[i].nValue); - } + here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 1); + MY_TSTALLOC(ASRCposptr[j++], ASRCbranch, here->ASRCtree->vars[i].nValue); } else if (here->ASRCtype == ASRC_CURRENT) { /* VCCS */ here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 2);