Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sun, 07 Feb 2016 03:35:36 UTC Commit: 95133ee30874e100ddc641289f164eb4c9d0734b https://github.com/geany/geany-plugins/commit/95133ee30874e100ddc641289f164e...
Log Message: ----------- debugger/gdb_mi: Do not allocate values when reading invalid input
Only allocate a value structure in parse_value() if the input actually contains a readable value, instead of destroying it if it doesn't.
This is particularly useful as the implementation of parse_value() itself recurses in order to discriminate a value from a result, which means that a value would be allocated and freed immediately for each result in the input.
This gives a speedup of about 10% on typical data.
Modified Paths: -------------- debugger/src/gdb_mi.c
Modified: debugger/src/gdb_mi.c 9 lines changed, 3 insertions(+), 6 deletions(-) =================================================================== @@ -211,15 +211,17 @@ static gboolean parse_result(struct gdb_mi_result *result, const gchar **p) * Actually, this is more permissive and allows mixed tuples/lists */ static struct gdb_mi_value *parse_value(const gchar **p) { - struct gdb_mi_value *val = g_malloc0(sizeof *val); + struct gdb_mi_value *val = NULL; if (**p == '"') { + val = g_malloc0(sizeof *val); val->type = GDB_MI_VAL_STRING; val->string = parse_cstring(p); } else if (**p == '{' || **p == '[') { struct gdb_mi_result *prev = NULL; + val = g_malloc0(sizeof *val); val->type = GDB_MI_VAL_LIST; gchar end = **p == '{' ? '}' : ']'; (*p)++; @@ -248,11 +250,6 @@ static struct gdb_mi_value *parse_value(const gchar **p) if (**p == end) (*p)++; } - else - { - gdb_mi_value_free(val); - val = NULL; - } return val; }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).