src: remove last_line from struct location
Pablo Neira Ayuso
maintainerPATCH 1/2 src: remove last_line from struct location
This 4 bytes field is never used, remove it.
This does not shrink struct location in x86_64 due to alignment.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/nftables.h | 1 - src/parser_bison.y | 3 +-- src/parser_json.c | 1 - src/scanner.l | 1 - 4 files changed, 1 insertion(+), 5 deletions(-)
include/nftables.h +0 -1
@@ -161,7 +161,6 @@ struct location {off_t line_offset;unsigned int first_line; -unsigned int last_line;unsigned int first_column;unsigned int last_column; };
src/parser_bison.y +1 -2
@@ -105,12 +105,11 @@ static void location_update(struct location *loc, struct location *rhs, int n) loc->line_offset = rhs[1].line_offset; loc->first_line = rhs[1].first_line; loc->first_column = rhs[1].first_column; - loc->last_line = rhs[n].last_line; loc->last_column = rhs[n].last_column; } else { loc->indesc = rhs[0].indesc; loc->line_offset = rhs[0].line_offset; - loc->first_line = loc->last_line = rhs[0].last_line; + loc->first_line = rhs[0].first_line; loc->first_column = loc->last_column = rhs[0].last_column; } }
src/parser_json.c +0 -1
@@ -123,7 +123,6 @@ static void json_lib_error(struct json_ctx *ctx, json_error_t *err) .indesc = &json_indesc, .line_offset = err->position - err->column, .first_line = err->line, - .last_line = err->line, .first_column = err->column,/* no information where problematic part ends :( */ .last_column = err->column,
src/scanner.l +0 -1
@@ -80,7 +80,6 @@ static void update_pos(struct parser_state *state, struct location *loc, { loc->indesc = state->indesc; loc->first_line = state->indesc->lineno; - loc->last_line = state->indesc->lineno; loc->first_column = state->indesc->column; loc->last_column = state->indesc->column + len - 1; state->indesc->column += len;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/2 src: shrink line_offset in struct location to 4 bytes
line_offset of 2^32 bytes should be enough.
This requires the removal of the last_line field (in a previous patch) to shrink struct expr to 112 bytes.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/nftables.h | 3 +-- src/scanner.l | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-)
include/nftables.h +1 -2
@@ -158,8 +158,7 @@ struct location {const struct input_descriptor *indesc;union {struct { -off_t line_offset; - +unsigned int line_offset;unsigned int first_line;unsigned int first_column;unsigned int last_column;
src/scanner.l +8 -1
@@ -88,8 +88,15 @@ static void update_pos(struct parser_state *state, struct location *loc, static void update_offset(struct parser_state *state, struct location *loc, unsigned int len) { + uint32_t line_offset; + state->indesc->token_offset += len; - loc->line_offset = state->indesc->line_offset; + if (state->indesc->line_offset > UINT32_MAX) + line_offset = UINT32_MAX; + else + line_offset = state->indesc->line_offset; + + loc->line_offset = line_offset; } static void reset_pos(struct parser_state *state, struct location *loc)
Signature · 1 line
2.30.2