mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Simplify the loop in virCommandRunRegex
Do not check for border iterator values inside the loop, move the code before/after the loop instead.
This commit is contained in:
parent
f01f62d43d
commit
cf4fb7d9a0
@ -2840,13 +2840,11 @@ virCommandRunRegex(virCommandPtr cmd,
|
|||||||
if (!p)
|
if (!p)
|
||||||
p = lines[k];
|
p = lines[k];
|
||||||
|
|
||||||
|
ngroup = 0;
|
||||||
for (i = 0; i < nregex; i++) {
|
for (i = 0; i < nregex; i++) {
|
||||||
if (regexec(®[i], p, nvars[i]+1, vars, 0) != 0)
|
if (regexec(®[i], p, nvars[i]+1, vars, 0) != 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
ngroup = 0;
|
|
||||||
|
|
||||||
/* NULL terminate each captured group in the line */
|
/* NULL terminate each captured group in the line */
|
||||||
for (j = 0; j < nvars[i]; j++) {
|
for (j = 0; j < nvars[i]; j++) {
|
||||||
/* NB vars[0] is the full pattern, so we offset j by 1 */
|
/* NB vars[0] is the full pattern, so we offset j by 1 */
|
||||||
@ -2855,16 +2853,14 @@ virCommandRunRegex(virCommandPtr cmd,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We're matching on the last regex, so callback time */
|
}
|
||||||
if (i == (nregex-1)) {
|
/* We've matched on the last regex, so callback time */
|
||||||
if (((*func)(groups, data)) < 0)
|
if (i == nregex) {
|
||||||
goto cleanup;
|
if (((*func)(groups, data)) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
/* Release matches & restart to matching the first regex */
|
for (j = 0; j < totgroups; j++)
|
||||||
for (j = 0; j < totgroups; j++)
|
VIR_FREE(groups[j]);
|
||||||
VIR_FREE(groups[j]);
|
|
||||||
ngroup = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user