Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/uu/sed/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::named_writer::NamedWriter;
use crate::script_char_provider::ScriptCharProvider;
use crate::script_line_provider::ScriptLineProvider;

use std::borrow::Cow;
use std::cell::RefCell;
use std::collections::HashMap;
use std::path::PathBuf; // For file descriptors and equivalent
Expand Down Expand Up @@ -74,7 +73,7 @@ pub struct ProcessingContext {
#[derive(Clone, Debug)]
/// Elements that shall be appended at the end of each command processing cycle
pub enum AppendElement {
Text(String), // The specified text string
Text(Rc<str>), // The specified text string
Path(PathBuf), // The contents of the specified file path
}

Expand Down Expand Up @@ -322,7 +321,7 @@ pub enum CommandData {
NamedWriter(Rc<RefCell<NamedWriter>>), // File output for 'w'
Number(usize), // Number for 'l', 'q', 'Q' (GNU)
Substitution(Box<Substitution>), // Substitute command 's'
Text(Cow<'static, str>), // Text for 'a', 'c', 'i'
Text(Rc<str>), // Text for 'a', 'c', 'i'
Transliteration(Box<Transliteration>), // Transliteration command 'y'
}

Expand Down
24 changes: 12 additions & 12 deletions src/uu/sed/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use crate::named_writer::NamedWriter;
use crate::script_char_provider::ScriptCharProvider;
use crate::script_line_provider::{ScriptLineProvider, ScriptValue};

use std::borrow::Cow;
use std::cell::RefCell;
use std::mem;
use std::path::PathBuf;
use std::rc::Rc;

use terminal_size::{Width, terminal_size};
use uucore::error::{UResult, USimpleError};

Expand Down Expand Up @@ -1105,7 +1105,7 @@ fn compile_text_command_gnu(
line.advance();
}
}
cmd.data = CommandData::Text(Cow::Owned(text));
cmd.data = CommandData::Text(Rc::from(text));
Ok(CommandHandling::Continue)
}

Expand Down Expand Up @@ -1151,7 +1151,7 @@ fn compile_text_command_posix(
break;
}
}
cmd.data = CommandData::Text(Cow::Owned(text));
cmd.data = CommandData::Text(Rc::from(text));
Ok(CommandHandling::Continue)
}

Expand Down Expand Up @@ -2541,7 +2541,7 @@ mod tests {
compile_text_command(&mut lines, &mut chars, &mut cmd, &mut context).unwrap();
match &cmd.data {
CommandData::Text(text) => {
assert_eq!(text, "line1\n");
assert_eq!(text.to_string(), "line1\n");
}
_ => panic!("Expected CommandData::Text"),
}
Expand All @@ -2558,7 +2558,7 @@ mod tests {
compile_text_command(&mut lines, &mut chars, &mut cmd, &mut context).unwrap();
match &cmd.data {
CommandData::Text(text) => {
assert_eq!(text, "line1\n");
assert_eq!(text.to_string(), "line1\n");
}
_ => panic!("Expected CommandData::Text"),
}
Expand All @@ -2574,7 +2574,7 @@ mod tests {
compile_text_command(&mut lines, &mut chars, &mut cmd, &mut context).unwrap();
match &cmd.data {
CommandData::Text(text) => {
assert_eq!(text, "there\n");
assert_eq!(text.to_string(), "there\n");
}
_ => panic!("Expected CommandData::Text"),
}
Expand All @@ -2590,7 +2590,7 @@ mod tests {
compile_text_command(&mut lines, &mut chars, &mut cmd, &mut context).unwrap();
match &cmd.data {
CommandData::Text(text) => {
assert_eq!(text, "there\n");
assert_eq!(text.to_string(), "there\n");
}
_ => panic!("Expected CommandData::Text"),
}
Expand All @@ -2606,7 +2606,7 @@ mod tests {
compile_text_command(&mut lines, &mut chars, &mut cmd, &mut context).unwrap();
match &cmd.data {
CommandData::Text(text) => {
assert_eq!(text, "\n");
assert_eq!(text.to_string(), "\n");
}
_ => panic!("Expected CommandData::Text"),
}
Expand All @@ -2622,7 +2622,7 @@ mod tests {
compile_text_command(&mut lines, &mut chars, &mut cmd, &mut context).unwrap();
match &cmd.data {
CommandData::Text(text) => {
assert_eq!(text, "");
assert_eq!(text.to_string(), "");
}
_ => panic!("Expected CommandData::Text"),
}
Expand All @@ -2638,7 +2638,7 @@ mod tests {
compile_text_command(&mut lines, &mut chars, &mut cmd, &mut context).unwrap();
match &cmd.data {
CommandData::Text(text) => {
assert_eq!(text, "tom\n");
assert_eq!(text.to_string(), "tom\n");
}
_ => panic!("Expected CommandData::Text"),
}
Expand All @@ -2654,7 +2654,7 @@ mod tests {
compile_text_command(&mut lines, &mut chars, &mut cmd, &mut context).unwrap();
match &cmd.data {
CommandData::Text(text) => {
assert_eq!(text, ">helll\x08o\nto\nall\x07\n");
assert_eq!(text.to_string(), ">helll\x08o\nto\nall\x07\n");
}
_ => panic!("Expected CommandData::Text"),
}
Expand All @@ -2670,7 +2670,7 @@ mod tests {
compile_text_command(&mut lines, &mut chars, &mut cmd, &mut context).unwrap();
match &cmd.data {
CommandData::Text(text) => {
assert_eq!(text, "line1\nline2\n");
assert_eq!(text.to_string(), "line1\nline2\n");
}
_ => panic!("Expected CommandData::Text"),
}
Expand Down
4 changes: 2 additions & 2 deletions src/uu/sed/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ fn flush_appends(output: &mut OutputBuffer, context: &mut ProcessingContext) ->
for elem in &context.append_elements {
match elem {
AppendElement::Text(text) => {
output.write_str(text.clone())?;
output.write_str(&**text)?;
}
AppendElement::Path(path) => {
output.copy_file(path)?;
Expand Down Expand Up @@ -476,7 +476,7 @@ fn process_file(
let text = extract_variant!(command, Text);
context
.append_elements
.push(AppendElement::Text(text.clone().into_owned()));
.push(AppendElement::Text(text.clone()));
}
'b' => {
// Branch to the specified label or end if none is given.
Expand Down
3 changes: 3 additions & 0 deletions util/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ bench_run access-log-translit "$PROG y/0123456789/9876543210/ access.log"
# Multiple substitutions
bench_run access-log-complex-sub "$PROG -f $SCRIPTS/http-log-redact.sed access.log"

# Text append
bench_run access-log-append "$PROG athe-line-ends-here access.log"

rm access.log

# Remove \r
Expand Down
Loading