diff options
author | Ben S <ogham@bsago.me> | 2014-11-24 02:01:08 +0000 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2014-11-24 02:01:08 +0000 |
commit | d72be30c30c0c57375736154fd6b5293cb04d0d8 (patch) | |
tree | a254fdddf168b96dc926f4315a81b07179c1a205 /src/file.rs | |
parent | c75bbf7f7951dc08dd1ecb71c1fceea79ba70963 (diff) |
Reduce unnecessary String allocations
- Remove uses of to_string() on a &str where it wasn't necessary
- Use SendStr to reduce allocations further
Diffstat (limited to 'src/file.rs')
-rw-r--r-- | src/file.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/file.rs b/src/file.rs index 43a7b06..dc45202 100644 --- a/src/file.rs +++ b/src/file.rs @@ -1,5 +1,6 @@ use std::io::{fs, IoResult}; use std::io; +use std::str::SendStr; use ansi_term::{Paint, Colour, Plain, Style, Red, Green, Yellow, Blue, Purple, Cyan, Fixed}; @@ -216,14 +217,14 @@ impl<'a> File<'a> { } } - fn type_char(&self) -> String { + fn type_char(&self) -> SendStr { return match self.stat.kind { - io::TypeFile => ".".to_string(), - io::TypeDirectory => Blue.paint("d"), - io::TypeNamedPipe => Yellow.paint("|"), - io::TypeBlockSpecial => Purple.paint("s"), - io::TypeSymlink => Cyan.paint("l"), - io::TypeUnknown => "?".to_string(), + io::TypeFile => ".".into_maybe_owned(), + io::TypeDirectory => Blue.paint("d").into_maybe_owned(), + io::TypeNamedPipe => Yellow.paint("|").into_maybe_owned(), + io::TypeBlockSpecial => Purple.paint("s").into_maybe_owned(), + io::TypeSymlink => Cyan.paint("l").into_maybe_owned(), + io::TypeUnknown => "?".into_maybe_owned(), } } |