mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 06:25:43 +02:00
Replace &Span
with Span
since Span
is Copy
(#9770)
# Description `Span` is `Copy`, so we probably should not be passing references of `Span` around. This PR replaces all instances of `&Span` with `Span`, copying spans where necessary. # User-Facing Changes This alters some public functions to take `Span` instead of `&Span` as input. Namely, `EngineState::get_span_contents`, `nu_protocol::extract_value`, a bunch of the math commands, and `Gstat::gstat`.
This commit is contained in:
@ -724,7 +724,7 @@ impl EngineState {
|
||||
output
|
||||
}
|
||||
|
||||
pub fn get_span_contents(&self, span: &Span) -> &[u8] {
|
||||
pub fn get_span_contents(&self, span: Span) -> &[u8] {
|
||||
for (contents, start, finish) in &self.file_contents {
|
||||
if span.start >= *start && span.end <= *finish {
|
||||
return &contents[(span.start - start)..(span.end - start)];
|
||||
@ -902,7 +902,7 @@ impl EngineState {
|
||||
pub fn build_usage(&self, spans: &[Span]) -> (String, String) {
|
||||
let comment_lines: Vec<&[u8]> = spans
|
||||
.iter()
|
||||
.map(|span| self.get_span_contents(span))
|
||||
.map(|span| self.get_span_contents(*span))
|
||||
.collect();
|
||||
build_usage(&comment_lines)
|
||||
}
|
||||
@ -1370,7 +1370,7 @@ impl<'a> StateWorkingSet<'a> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return self.permanent_state.get_span_contents(&span);
|
||||
return self.permanent_state.get_span_contents(span);
|
||||
}
|
||||
|
||||
panic!("internal error: missing span contents in file cache")
|
||||
|
Reference in New Issue
Block a user