avoid allocation on lookup of $fish_trace

Looking up a variable by a string literal implicitly constructs a wcstring.
By avoiding that, we get a noticeable reduction of temporary allocations.

$ HOME=. heaptrack ./fish -c true
heaptrack stats:			# baseline
        allocations:            7635
        leaked allocations:     3277
        temporary allocations:  602
heaptrack stats:			# new
        allocations:            7565
        leaked allocations:     3267
        temporary allocations:  530
This commit is contained in:
Johannes Altmanninger 2019-12-16 12:56:30 +01:00
parent b1144a1fde
commit 24562a9f49

View file

@ -6,11 +6,13 @@
#include "flog.h"
#include "parser.h"
static const wcstring VAR_fish_trace = L"fish_trace";
bool trace_enabled(const parser_t &parser) {
auto &ld = parser.libdata();
if (ld.suppress_fish_trace) return false;
// TODO: this variable lookup is somewhat expensive, consider how to make this cheaper.
return !parser.vars().get(L"fish_trace").missing_or_empty();
return !parser.vars().get(VAR_fish_trace).missing_or_empty();
}
/// Trace an "argv": a list of arguments where the first is the command.