mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
device_mapper: store string on stack
Instead of allocating string from a pool, for shorted strings use buffer on stack since the string after the use in _find_or_make_node() as no longer needed. Eventually we may enhance code also for TOK_STRING_ESCAPED and TOK_STRING, but they appear to be unused for _section().
This commit is contained in:
parent
c29e3410c9
commit
d8996a2a12
@ -592,6 +592,8 @@ static struct dm_config_node *_section(struct parser *p, struct dm_config_node *
|
||||
struct dm_config_node *root;
|
||||
struct dm_config_value *value;
|
||||
char *str;
|
||||
size_t len;
|
||||
char buf[8192];
|
||||
|
||||
if (p->t == TOK_STRING_ESCAPED) {
|
||||
if (!(str = _dup_string_tok(p)))
|
||||
@ -605,9 +607,16 @@ static struct dm_config_node *_section(struct parser *p, struct dm_config_node *
|
||||
|
||||
match(TOK_STRING);
|
||||
} else {
|
||||
if (!(str = _dup_tok(p)))
|
||||
return_NULL;
|
||||
|
||||
len = p->te - p->tb;
|
||||
if (len < (sizeof(buf) - 1)) {
|
||||
/* Use stack for smaller string */
|
||||
str = buf;
|
||||
memcpy(str, p->tb, len);
|
||||
str[len] = '\0';
|
||||
} else {
|
||||
if (!(str = _dup_tok(p)))
|
||||
return_NULL;
|
||||
}
|
||||
match(TOK_IDENTIFIER);
|
||||
}
|
||||
|
||||
|
@ -592,6 +592,8 @@ static struct dm_config_node *_section(struct parser *p, struct dm_config_node *
|
||||
struct dm_config_node *root;
|
||||
struct dm_config_value *value;
|
||||
char *str;
|
||||
size_t len;
|
||||
char buf[8192];
|
||||
|
||||
if (p->t == TOK_STRING_ESCAPED) {
|
||||
if (!(str = _dup_string_tok(p)))
|
||||
@ -605,9 +607,16 @@ static struct dm_config_node *_section(struct parser *p, struct dm_config_node *
|
||||
|
||||
match(TOK_STRING);
|
||||
} else {
|
||||
if (!(str = _dup_tok(p)))
|
||||
return_NULL;
|
||||
|
||||
len = p->te - p->tb;
|
||||
if (len < (sizeof(buf) - 1)) {
|
||||
/* Use stack for smaller string */
|
||||
str = buf;
|
||||
memcpy(str, p->tb, len);
|
||||
str[len] = '\0';
|
||||
} else {
|
||||
if (!(str = _dup_tok(p)))
|
||||
return_NULL;
|
||||
}
|
||||
match(TOK_IDENTIFIER);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user