When we're cleaning out the lists in parse_config and conf_clear it's a

lot simpler just to do while (entry = TAILQ_FIRST(head)) than to do a
for () over the whole lot. Simpler, shorter and probably faster.

ok okan@
This commit is contained in:
oga 2008-05-18 19:34:09 +00:00
parent 0f50af616e
commit a21a064a9b

52
parse.y
View File

@ -466,28 +466,22 @@ popfile(void)
void void
conf_clear(struct conf *c) conf_clear(struct conf *c)
{ {
struct autogroupwin *ag, *agnext; struct autogroupwin *ag;
struct keybinding *kb, *kbnext; struct keybinding *kb;
struct winmatch *wm, *wmnext; struct winmatch *wm;
struct cmd *cmd, *cmdnext; struct cmd *cmd;
for (cmd = TAILQ_FIRST(&c->cmdq); cmd != NULL; cmd = cmdnext) {
cmdnext = TAILQ_NEXT(cmd, entry);
while (cmd = TAILQ_FIRST(&c->cmdq)) {
TAILQ_REMOVE(&c->cmdq, cmd, entry); TAILQ_REMOVE(&c->cmdq, cmd, entry);
free(cmd); free(cmd);
} }
for (kb = TAILQ_FIRST(&c->keybindingq); kb != NULL; kb = kbnext) { while (kb = TAILQ_FIRST(&c->keybindingq)) {
kbnext = TAILQ_NEXT(kb, entry);
TAILQ_REMOVE(&c->keybindingq, kb, entry); TAILQ_REMOVE(&c->keybindingq, kb, entry);
free(kb); free(kb);
} }
for (ag = TAILQ_FIRST(&c->autogroupq); ag != NULL; ag = agnext) { while (ag = TAILQ_FIRST(&c->autogroupq)) {
agnext = TAILQ_NEXT(ag, entry);
TAILQ_REMOVE(&c->autogroupq, ag, entry); TAILQ_REMOVE(&c->autogroupq, ag, entry);
free(ag->class); free(ag->class);
if (ag->name) if (ag->name)
@ -496,9 +490,7 @@ conf_clear(struct conf *c)
free(ag); free(ag);
} }
for (wm = TAILQ_FIRST(&c->ignoreq); wm != NULL; wm = wmnext) { while (wm = TAILQ_FIRST(&c->ignoreq)) {
wmnext = TAILQ_NEXT(wm, entry);
TAILQ_REMOVE(&c->ignoreq, wm, entry); TAILQ_REMOVE(&c->ignoreq, wm, entry);
free(wm); free(wm);
} }
@ -534,43 +526,31 @@ parse_config(const char *filename, struct conf *xconf)
conf_clear(conf); conf_clear(conf);
} }
else { else {
struct autogroupwin *ag, *agnext; struct autogroupwin *ag;
struct keybinding *kb, *kbnext; struct keybinding *kb;
struct winmatch *wm, *wmnext; struct winmatch *wm;
struct cmd *cmd, *cmdnext; struct cmd *cmd;
conf_clear(xconf); conf_clear(xconf);
xconf->flags = conf->flags; xconf->flags = conf->flags;
for (cmd = TAILQ_FIRST(&conf->cmdq); cmd != NULL; while (cmd = TAILQ_FIRST(&conf->cmdq)) {
cmd = cmdnext) {
cmdnext = TAILQ_NEXT(cmd, entry);
TAILQ_REMOVE(&conf->cmdq, cmd, entry); TAILQ_REMOVE(&conf->cmdq, cmd, entry);
TAILQ_INSERT_TAIL(&xconf->cmdq, cmd, entry); TAILQ_INSERT_TAIL(&xconf->cmdq, cmd, entry);
} }
for (kb = TAILQ_FIRST(&conf->keybindingq); kb != NULL; while (kb = TAILQ_FIRST(&conf->keybindingq)) {
kb = kbnext) {
kbnext = TAILQ_NEXT(kb, entry);
TAILQ_REMOVE(&conf->keybindingq, kb, entry); TAILQ_REMOVE(&conf->keybindingq, kb, entry);
TAILQ_INSERT_TAIL(&xconf->keybindingq, kb, entry); TAILQ_INSERT_TAIL(&xconf->keybindingq, kb, entry);
} }
for (ag = TAILQ_FIRST(&conf->autogroupq); ag != NULL; while (ag = TAILQ_FIRST(&conf->autogroupq)) {
ag = agnext) {
agnext = TAILQ_NEXT(ag, entry);
TAILQ_REMOVE(&conf->autogroupq, ag, entry); TAILQ_REMOVE(&conf->autogroupq, ag, entry);
TAILQ_INSERT_TAIL(&xconf->autogroupq, ag, entry); TAILQ_INSERT_TAIL(&xconf->autogroupq, ag, entry);
} }
for (wm = TAILQ_FIRST(&conf->ignoreq); wm != NULL; while (wm = TAILQ_FIRST(&conf->ignoreq)) {
wm = wmnext) {
wmnext = TAILQ_NEXT(wm, entry);
TAILQ_REMOVE(&conf->ignoreq, wm, entry); TAILQ_REMOVE(&conf->ignoreq, wm, entry);
TAILQ_INSERT_TAIL(&xconf->ignoreq, wm, entry); TAILQ_INSERT_TAIL(&xconf->ignoreq, wm, entry);
} }