mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
uniq: do not allocate a new string in skip_fields
Instead, reuse the existing line and just view into that.
This commit is contained in:
parent
32ec6646a3
commit
d624dbcfa0
1 changed files with 5 additions and 5 deletions
|
@ -72,7 +72,7 @@ impl Uniq {
|
|||
}
|
||||
}
|
||||
|
||||
fn skip_fields(&self, line: &str) -> String {
|
||||
fn skip_fields<'a>(&self, line: &'a str) -> &'a str {
|
||||
if let Some(skip_fields) = self.skip_fields {
|
||||
if line.split_whitespace().count() > skip_fields {
|
||||
let mut field = 0;
|
||||
|
@ -86,12 +86,12 @@ impl Uniq {
|
|||
}
|
||||
field = field + 1;
|
||||
}
|
||||
line[i..].to_owned()
|
||||
&line[i..]
|
||||
} else {
|
||||
"".to_owned()
|
||||
""
|
||||
}
|
||||
} else {
|
||||
line[..].to_owned()
|
||||
line
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ impl Uniq {
|
|||
}
|
||||
|
||||
fn cmp_key(&self, line: &str) -> String {
|
||||
let fields_to_check = &self.skip_fields(line);
|
||||
let fields_to_check = self.skip_fields(line);
|
||||
let len = fields_to_check.len();
|
||||
if len > 0 {
|
||||
fields_to_check
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue