From 025c1e751e986cc884dd6de2a0f4a870c3887bc4 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 30 Jun 2013 11:38:12 +0200 Subject: [PATCH] abstraction, new function `find_instance()' --- src/spicelib/devices/cktfinddev.c | 32 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/spicelib/devices/cktfinddev.c b/src/spicelib/devices/cktfinddev.c index 2db4ff231..4956073c5 100644 --- a/src/spicelib/devices/cktfinddev.c +++ b/src/spicelib/devices/cktfinddev.c @@ -10,6 +10,17 @@ Author: 1985 Thomas L. Quarles #include "string.h" +static GENinstance * +find_instance(GENinstance *here, IFuid name) +{ + for (; here; here = here->GENnextInstance) + if (here->GENname == name) + return here; + + return NULL; +} + + int CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name, GENmodel *modfast, IFuid modname) { @@ -28,8 +39,8 @@ CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name, GENmodel * if(modfast) { /* have model, just need device */ mods = modfast; - for (here = mods->GENinstances; here != NULL; here = here->GENnextInstance) { - if (here->GENname == name) { + here = find_instance(mods->GENinstances, name); + if (here) { if (fast != NULL) *fast = here; @@ -38,7 +49,6 @@ CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name, GENmodel * return OK; } - } return E_NODEV; } @@ -51,16 +61,12 @@ CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name, GENmodel * { /* and all instances */ if (modname == NULL || mods->GENmodName == modname) { - for (here = mods->GENinstances; - here != NULL; - here = here->GENnextInstance) - { - if (here->GENname == name) { + here = find_instance(mods->GENinstances, name); + if (here) { if (fast != 0) *fast = here; return OK; } - } if(mods->GENmodName == modname) { return E_NODEV; } @@ -77,16 +83,12 @@ CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name, GENmodel * { /* and all instances */ if(modname == NULL || mods->GENmodName == modname) { - for (here = mods->GENinstances; - here != NULL; - here = here->GENnextInstance) - { - if (here->GENname == name) { + here = find_instance(mods->GENinstances, name); + if (here) { if(fast != 0) *fast = here; return OK; } - } if(mods->GENmodName == modname) { return E_NODEV; }