move String instead of re-alloc

pull/14/head
chris west 4 years ago
parent 9c64f7c420
commit 89291da67b

@ -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());
};
}

@ -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,

@ -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));

Loading…
Cancel
Save