mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-20 03:32:44 +08:00
separated_buffer_t to accept strings by rvalue reference
This saves a copy in some cases.
This commit is contained in:
parent
032467f338
commit
d578f8d136
12
src/io.h
12
src/io.h
|
@ -152,9 +152,15 @@ class separated_buffer_t {
|
|||
}
|
||||
|
||||
/// Append a string \p str with the given separation type \p sep.
|
||||
void append(const std::string &str, separation_type_t sep = separation_type_t::inferred) {
|
||||
const char *cstr = str.c_str();
|
||||
append(cstr, cstr + str.size(), sep);
|
||||
void append(std::string &&str, separation_type_t sep = separation_type_t::inferred) {
|
||||
if (!try_add_size(str.size())) return;
|
||||
// Try merging with the last element.
|
||||
if (sep == separation_type_t::inferred && !elements_.empty() &&
|
||||
!elements_.back().is_explicitly_separated()) {
|
||||
elements_.back().contents.append(str);
|
||||
} else {
|
||||
elements_.emplace_back(std::move(str), sep);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user