From 24562a9f49e06ce1cf62448911407dc6c4fd757e Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 16 Dec 2019 12:56:30 +0100 Subject: [PATCH] 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 --- src/trace.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/trace.cpp b/src/trace.cpp index 03b6481db..d7968c9c4 100644 --- a/src/trace.cpp +++ b/src/trace.cpp @@ -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.