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
0e46a12e01
commit
c1ba82bcc9
1 changed files with 5 additions and 5 deletions
|
@ -53,6 +53,7 @@ struct git_parser_state {
|
||||||
struct divelog *log = nullptr;
|
struct divelog *log = nullptr;
|
||||||
int o2pressure_sensor = 0;
|
int o2pressure_sensor = 0;
|
||||||
std::vector<std::string> converted_strings;
|
std::vector<std::string> converted_strings;
|
||||||
|
size_t act_converted_string = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct keyword_action {
|
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)
|
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);
|
report_error("git-load: string marker without any strings ('%s')", err);
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
std::string res = std::move(state->converted_strings.front());
|
size_t idx = state->act_converted_string++;
|
||||||
// This copies the whole vector. Keep an index instead!
|
return std::move(state->converted_strings[idx]);
|
||||||
state->converted_strings.erase(state->converted_strings.begin());
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse key=val parts of samples and cylinders etc */
|
/* 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) {
|
while (size) {
|
||||||
state->converted_strings.clear();
|
state->converted_strings.clear();
|
||||||
|
state->act_converted_string = 0;
|
||||||
unsigned int n = parse_one_line(content, size, fn, state);
|
unsigned int n = parse_one_line(content, size, fn, state);
|
||||||
content += n;
|
content += n;
|
||||||
size -= n;
|
size -= n;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue