mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: avoid pointless copying in git parser
When iterating over the converted strings of a line, the first entry of the array would be popped off, leading to a full copy of the remaining array. Instead, use an index in the parser state. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
885ff44c56
commit
6bf8cbfe46
1 changed files with 5 additions and 5 deletions
|
@ -53,6 +53,7 @@ struct git_parser_state {
|
|||
struct divelog *log = nullptr;
|
||||
int o2pressure_sensor = 0;
|
||||
std::vector<std::string> converted_strings;
|
||||
size_t act_converted_string = 0;
|
||||
};
|
||||
|
||||
struct keyword_action {
|
||||
|
@ -337,14 +338,12 @@ static void parse_site_geo(char *line, struct git_parser_state *state)
|
|||
|
||||
static std::string pop_cstring(struct git_parser_state *state, const char *err)
|
||||
{
|
||||
if (state->converted_strings.empty()) {
|
||||
if (state->act_converted_string >= state->converted_strings.size()) {
|
||||
report_error("git-load: string marker without any strings ('%s')", err);
|
||||
return std::string();
|
||||
}
|
||||
std::string res = std::move(state->converted_strings.front());
|
||||
// This copies the whole vector. Keep an index instead!
|
||||
state->converted_strings.erase(state->converted_strings.begin());
|
||||
return res;
|
||||
size_t idx = state->act_converted_string++;
|
||||
return std::move(state->converted_strings[idx]);
|
||||
}
|
||||
|
||||
/* Parse key=val parts of samples and cylinders etc */
|
||||
|
@ -1365,6 +1364,7 @@ static void for_each_line(git_blob *blob, line_fn_t *fn, struct git_parser_state
|
|||
|
||||
while (size) {
|
||||
state->converted_strings.clear();
|
||||
state->act_converted_string = 0;
|
||||
unsigned int n = parse_one_line(content, size, fn, state);
|
||||
content += n;
|
||||
size -= n;
|
||||
|
|
Loading…
Add table
Reference in a new issue