mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-11 20:58:50 +03:00
Optimise _eat_space and _get_token
Makes the code more readable and has a smaller number of memory accesses thus it's small optimisation as well. For _get_token() optimize number parsing. Check for '.' char only if it's not a digit. Move pointer incrementation into one place. For _eat_space() check only p->te for '\0' in skipping of comment line. Avoid check for '\0' when we know it is space. Also master while loop doesn't need checking p->tb for '\0'. We just need to check p->tb isn't already at the end of buffer. This could give 'extra' loop cycle if we are already there - but safes memory access in every other case.
This commit is contained in:
parent
36b9ec636d
commit
027a55d0fb
@ -1,5 +1,6 @@
|
|||||||
Version 2.02.85 -
|
Version 2.02.85 -
|
||||||
===================================
|
===================================
|
||||||
|
Optimise _get_token() and _eat_space().
|
||||||
Add _lv_postorder_vg() to improve efficiency for all LVs in VG.
|
Add _lv_postorder_vg() to improve efficiency for all LVs in VG.
|
||||||
Use hash tables to speedup string search in validate_vg().
|
Use hash tables to speedup string search in validate_vg().
|
||||||
Refactor allocation of VG structure, add alloc_vg().
|
Refactor allocation of VG structure, add alloc_vg().
|
||||||
|
@ -822,18 +822,20 @@ static void _get_token(struct parser *p, int tok_prev)
|
|||||||
case '+':
|
case '+':
|
||||||
case '-':
|
case '-':
|
||||||
if (values_allowed) {
|
if (values_allowed) {
|
||||||
te++;
|
while (++te != p->fe) {
|
||||||
while ((te != p->fe) && (*te)) {
|
if (!isdigit((int) *te)) {
|
||||||
if (*te == '.') {
|
if (*te == '.') {
|
||||||
if (p->t == TOK_FLOAT)
|
if (p->t != TOK_FLOAT) {
|
||||||
break;
|
p->t = TOK_FLOAT;
|
||||||
p->t = TOK_FLOAT;
|
continue;
|
||||||
} else if (!isdigit((int) *te))
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
te++;
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* fall through */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
p->t = TOK_IDENTIFIER;
|
p->t = TOK_IDENTIFIER;
|
||||||
@ -850,22 +852,20 @@ static void _get_token(struct parser *p, int tok_prev)
|
|||||||
|
|
||||||
static void _eat_space(struct parser *p)
|
static void _eat_space(struct parser *p)
|
||||||
{
|
{
|
||||||
while ((p->tb != p->fe) && (*p->tb)) {
|
while (p->tb != p->fe) {
|
||||||
if (*p->te == '#')
|
if (*p->te == '#')
|
||||||
while ((p->te != p->fe) && (*p->te) && (*p->te != '\n'))
|
while ((p->te != p->fe) && (*p->te != '\n') && (*p->te))
|
||||||
p->te++;
|
++p->te;
|
||||||
|
|
||||||
else if (isspace(*p->te)) {
|
else if (!isspace(*p->te))
|
||||||
while ((p->te != p->fe) && (*p->te) && isspace(*p->te)) {
|
break;
|
||||||
if (*p->te == '\n')
|
|
||||||
p->line++;
|
while ((p->te != p->fe) && isspace(*p->te)) {
|
||||||
p->te++;
|
if (*p->te == '\n')
|
||||||
}
|
++p->line;
|
||||||
|
++p->te;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
|
|
||||||
p->tb = p->te;
|
p->tb = p->te;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user