mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Implement and use make_unique
Allows avoiding some explicit calls to new(), which can look suspicious
This commit is contained in:
parent
5b108efde4
commit
ac8b27fcb1
3 changed files with 10 additions and 5 deletions
|
@ -572,9 +572,9 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar
|
|||
|
||||
std::unique_ptr<string_matcher_t> matcher;
|
||||
if (regex) {
|
||||
matcher.reset(new pcre2_matcher_t(argv[0], pattern, opts, streams));
|
||||
matcher = make_unique<pcre2_matcher_t>(argv[0], pattern, opts, streams);
|
||||
} else {
|
||||
matcher.reset(new wildcard_matcher_t(argv[0], pattern, opts, streams));
|
||||
matcher = make_unique<wildcard_matcher_t>(argv[0], pattern, opts, streams);
|
||||
}
|
||||
|
||||
const wchar_t *arg;
|
||||
|
|
|
@ -644,6 +644,12 @@ wcstring vformat_string(const wchar_t *format, va_list va_orig);
|
|||
void append_format(wcstring &str, const wchar_t *format, ...);
|
||||
void append_formatv(wcstring &str, const wchar_t *format, va_list ap);
|
||||
|
||||
/// make_unique implementation
|
||||
template<typename T, typename... Args>
|
||||
std::unique_ptr<T> make_unique(Args&&... args) {
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
/// This functions returns the end of the quoted substring beginning at \c in. The type of quoting
|
||||
/// character is detemrined by examining \c in. Returns 0 on error.
|
||||
///
|
||||
|
|
|
@ -573,7 +573,7 @@ job_t *parser_t::job_get_from_pid(int pid) {
|
|||
profile_item_t *parser_t::create_profile_item() {
|
||||
profile_item_t *result = nullptr;
|
||||
if (g_profiling_active) {
|
||||
profile_items.emplace_back(new profile_item_t());
|
||||
profile_items.push_back(make_unique<profile_item_t>());
|
||||
result = profile_items.back().get();
|
||||
}
|
||||
return result;
|
||||
|
@ -612,8 +612,7 @@ int parser_t::eval_acquiring_tree(const wcstring &cmd, const io_chain_t &io,
|
|||
(execution_contexts.empty() ? -1 : execution_contexts.back()->current_eval_level());
|
||||
|
||||
// Append to the execution context stack.
|
||||
// Note usage of unique_ptr, so we don't have to delete
|
||||
execution_contexts.emplace_back(new parse_execution_context_t(tree, cmd, this, exec_eval_level));
|
||||
execution_contexts.push_back(make_unique<parse_execution_context_t>(tree, cmd, this, exec_eval_level));
|
||||
const parse_execution_context_t *ctx = execution_contexts.back().get();
|
||||
|
||||
// Execute the first node.
|
||||
|
|
Loading…
Reference in a new issue