From d624dbcfa0e3a017d454c636042ab64b5f4f2f6a Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Thu, 12 Jul 2018 00:00:22 +0200 Subject: [PATCH] uniq: do not allocate a new string in skip_fields Instead, reuse the existing line and just view into that. --- src/uniq/uniq.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uniq/uniq.rs b/src/uniq/uniq.rs index 5b27e9549..78e066dc2 100644 --- a/src/uniq/uniq.rs +++ b/src/uniq/uniq.rs @@ -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