diff --git a/src/spicelib/devices/bsim4/b4reliability.c b/src/spicelib/devices/bsim4/b4reliability.c index 354cfda59..0b2fa36b1 100644 --- a/src/spicelib/devices/bsim4/b4reliability.c +++ b/src/spicelib/devices/bsim4/b4reliability.c @@ -12,23 +12,22 @@ listInsert (BSIM4vgsList **list, double vgs) { BSIM4vgsList *current, *previous ; - /* Loop until the end of the list */ - previous = NULL ; - current = *list ; - while (current != NULL) - { - previous = current ; - current = current->next ; - } + /* create a new 'list' or add an element. + 'last' contains the address of the last element */ + if (*list) + previous = (*list)->last; + else + previous = NULL; /* Insert the new element into the list */ if (previous == NULL) { - *list = TMALLOC (BSIM4vgsList, 1) ; - current = *list ; - } else { - current = TMALLOC (BSIM4vgsList, 1) ; - previous->next = current ; + *list = TMALLOC(BSIM4vgsList, 1); + (*list)->last = current = *list; + } + else { + current = TMALLOC(BSIM4vgsList, 1); + (*list)->last = previous->next = current; } /* Populate the element */ diff --git a/src/spicelib/devices/bsim4/bsim4def.h b/src/spicelib/devices/bsim4/bsim4def.h index 0eac70157..a807174b8 100644 --- a/src/spicelib/devices/bsim4/bsim4def.h +++ b/src/spicelib/devices/bsim4/bsim4def.h @@ -35,6 +35,7 @@ Modified by Pankaj Kumar Thakur, 07/23/2012 typedef struct sBSIM4vgsList { double vgs ; struct sBSIM4vgsList *next ; + struct sBSIM4vgsList *last ; } BSIM4vgsList ; #endif diff --git a/src/spicelib/devices/relmodel/relmodelcalcaging.c b/src/spicelib/devices/relmodel/relmodelcalcaging.c index 25abb7ae8..6caa6a0ab 100644 --- a/src/spicelib/devices/relmodel/relmodelcalcaging.c +++ b/src/spicelib/devices/relmodel/relmodelcalcaging.c @@ -19,23 +19,21 @@ listInsert (RELMODELrelList **list, double time, double deltaVth) RELMODELrelList *current ; RELMODELrelList *previous ; - /* Loop until the end of the list */ - previous = NULL ; - current = *list ; - while (current != NULL) - { - previous = current ; - current = current->next ; - } + /* create a new 'list' or add an element. + 'last' contains the address of the last element */ + if (*list) + previous = (*list)->last; + else + previous = NULL; /* Insert the new element into the list */ if (previous == NULL) { *list = TMALLOC (RELMODELrelList, 1) ; - current = *list ; + (*list)->last = current = *list ; } else { current = TMALLOC (RELMODELrelList, 1) ; - previous->next = current ; + (*list)->last = previous->next = current ; } /* Populate the element */ diff --git a/src/spicelib/devices/relmodel/relmodeldefs.h b/src/spicelib/devices/relmodel/relmodeldefs.h index 5226540c9..efe96a66e 100644 --- a/src/spicelib/devices/relmodel/relmodeldefs.h +++ b/src/spicelib/devices/relmodel/relmodeldefs.h @@ -15,6 +15,7 @@ typedef struct sRELMODELrelList { double time ; double deltaVth ; struct sRELMODELrelList *next ; + struct sRELMODELrelList *last ; } RELMODELrelList ; typedef struct sRELMODELrelStruct {