Skip to content

Commit

Permalink
[item] reudce some overhead on consuming input
Browse files Browse the repository at this point in the history
replace from_utf8_lossy with from_utf8_unchecked
  • Loading branch information
lotabout committed Sep 2, 2018
1 parent b170a0e commit 49285dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct Item {

impl<'a> Item {
pub fn new(
orig_text: Cow<str>,
orig_text: String,
ansi_enabled: bool,
trans_fields: &[FieldRange],
matching_fields: &[FieldRange],
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<'a> Item {

let mut ret = Item {
index: index,
output_text: orig_text.into_owned(),
output_text: orig_text,
text: text,
chars: Vec::new(),
ansi_states: states_text,
Expand Down
7 changes: 6 additions & 1 deletion src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,14 @@ fn reader(
buffer.pop();
}

let content = unsafe {
String::from_utf8_unchecked(
mem::replace(&mut buffer, Vec::with_capacity(100)))
};

debug!("reader:reader: create new item. index = {}", index);
let item = Item::new(
String::from_utf8_lossy(&buffer),
content,
opt.use_ansi_color,
&opt.transform_fields,
&opt.matching_fields,
Expand Down

0 comments on commit 49285dd

Please sign in to comment.