From 89291da67b29e3c3900572294579d458126b8f50 Mon Sep 17 00:00:00 2001 From: chris west Date: Tue, 14 Jan 2020 20:18:36 -0800 Subject: [PATCH] move String instead of re-alloc --- src/menu.rs | 8 ++++---- src/text.rs | 4 ++-- src/ui.rs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/menu.rs b/src/menu.rs index 9f212bc..3a2c594 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -113,7 +113,7 @@ impl View for Menu { impl Menu { /// Create a representation of a Gopher Menu from a raw Gopher /// response and a few options. - pub fn from(url: &str, response: &str, tls: bool, tor: bool) -> Menu { + pub fn from(url: &str, response: String, tls: bool, tor: bool) -> Menu { Menu { tls, tor, @@ -760,7 +760,7 @@ impl Menu { } /// Parse gopher response into a Menu object. - pub fn parse(url: &str, raw: &str) -> Menu { + pub fn parse(url: &str, raw: String) -> Menu { let mut lines = vec![]; let mut links = vec![]; let mut longest = 0; @@ -788,7 +788,7 @@ impl Menu { lines, links, longest, - raw: url.into(), + raw, input: String::new(), link: 0, mode: Default::default(), @@ -866,7 +866,7 @@ mod tests { macro_rules! parse { ($s:literal) => { - Menu::parse("test", $s); + Menu::parse("test", $s.to_string()); }; } diff --git a/src/text.rs b/src/text.rs index 654613c..84b4df9 100644 --- a/src/text.rs +++ b/src/text.rs @@ -161,7 +161,7 @@ impl View for Text { impl Text { /// Create a Text View from a raw Gopher response and a few options. - pub fn from(url: &str, response: &str, tls: bool, tor: bool) -> Text { + pub fn from(url: &str, response: String, tls: bool, tor: bool) -> Text { let mut lines = 0; let mut longest = 0; for line in response.split_terminator('\n') { @@ -173,7 +173,7 @@ impl Text { Text { url: url.into(), - raw_response: response.into(), + raw_response: response, scroll: 0, lines, longest, diff --git a/src/ui.rs b/src/ui.rs index 95ad620..3427be0 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -246,8 +246,8 @@ impl UI { }; let (typ, _, _, _) = gopher::parse_url(&url); match typ { - Type::Menu | Type::Search => Ok(Box::new(Menu::from(url, &res, tls, tor))), - Type::Text | Type::HTML => Ok(Box::new(Text::from(url, &res, tls, tor))), + Type::Menu | Type::Search => Ok(Box::new(Menu::from(url, res, tls, tor))), + Type::Text | Type::HTML => Ok(Box::new(Text::from(url, res, tls, tor))), _ => Err(error!("Unsupported Gopher Response: {:?}", typ)), } } @@ -258,7 +258,7 @@ impl UI { &url.trim_start_matches("gopher://phetch/") .trim_start_matches("1/"), ) { - Ok(Box::new(Menu::from(url, &source, false, false))) + Ok(Box::new(Menu::from(url, source, false, false))) } else { Err(error!("phetch URL not found: {}", url)) } @@ -584,7 +584,7 @@ impl UI { 'r' => { if let Some(page) = self.views.get(self.focused) { let url = page.url(); - let raw = page.raw(); + let raw = page.raw().to_string(); let mut text = Text::from(url, raw, page.is_tls(), page.is_tor()); text.wide = true; self.add_page(Box::new(text));