mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-15 22:44:01 +00:00
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:
parent
b1144a1fde
commit
24562a9f49
1 changed files with 3 additions and 1 deletions
|
@ -6,11 +6,13 @@
|
||||||
#include "flog.h"
|
#include "flog.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
|
static const wcstring VAR_fish_trace = L"fish_trace";
|
||||||
|
|
||||||
bool trace_enabled(const parser_t &parser) {
|
bool trace_enabled(const parser_t &parser) {
|
||||||
auto &ld = parser.libdata();
|
auto &ld = parser.libdata();
|
||||||
if (ld.suppress_fish_trace) return false;
|
if (ld.suppress_fish_trace) return false;
|
||||||
// TODO: this variable lookup is somewhat expensive, consider how to make this cheaper.
|
// 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.
|
/// Trace an "argv": a list of arguments where the first is the command.
|
||||||
|
|
Loading…
Reference in a new issue