mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-23 10:15:41 +00:00
Bug 1487994: webdriver: avoid unnecessary passing by value; r=whimboo
In some places we pass variables by value unnecessarily. In these cases it would be more memory efficient to pass a reference so that we avoid copying.
This commit is contained in:
parent
292ccb492a
commit
c988c68b51
@ -100,7 +100,7 @@ impl<U: WebDriverExtensionRoute> WebDriverMessage<U> {
|
||||
}
|
||||
|
||||
pub fn from_http(
|
||||
match_type: Route<U>,
|
||||
match_type: &Route<U>,
|
||||
params: &Captures,
|
||||
raw_body: &str,
|
||||
requires_body: bool,
|
||||
|
@ -323,7 +323,7 @@ impl<U: WebDriverExtensionRoute> RequestMatcher<U> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_match<'t>(&'t self, method: Method, path: &'t str) -> (bool, Option<Captures>) {
|
||||
pub fn get_match<'t>(&'t self, method: &Method, path: &'t str) -> (bool, Option<Captures>) {
|
||||
let captures = self.path_regexp.captures(path);
|
||||
(method == self.method, captures)
|
||||
}
|
||||
@ -342,10 +342,10 @@ impl<U: WebDriverExtensionRoute> RequestMatcher<U> {
|
||||
rv.push_str(&format!("{}/", component)[..]);
|
||||
}
|
||||
}
|
||||
//Remove the trailing /
|
||||
// Remove the trailing /
|
||||
rv.pop();
|
||||
rv.push_str("$");
|
||||
//This will fail at runtime if the regexp is invalid
|
||||
// This will fail at runtime if the regexp is invalid
|
||||
Regex::new(&rv[..]).unwrap()
|
||||
}
|
||||
}
|
||||
@ -379,18 +379,18 @@ impl<U: WebDriverExtensionRoute> WebDriverHttpApi<U> {
|
||||
|
||||
pub fn decode_request(
|
||||
&self,
|
||||
method: Method,
|
||||
method: &Method,
|
||||
path: &str,
|
||||
body: &str,
|
||||
) -> WebDriverResult<WebDriverMessage<U>> {
|
||||
let mut error = ErrorStatus::UnknownPath;
|
||||
for &(ref match_method, ref matcher) in self.routes.iter() {
|
||||
if method == *match_method {
|
||||
let (method_match, captures) = matcher.get_match(method.clone(), path);
|
||||
let (method_match, captures) = matcher.get_match(method, path);
|
||||
if captures.is_some() {
|
||||
if method_match {
|
||||
return WebDriverMessage::from_http(
|
||||
matcher.match_type.clone(),
|
||||
&matcher.match_type,
|
||||
&captures.unwrap(),
|
||||
body,
|
||||
method == Method::POST,
|
||||
|
@ -63,7 +63,7 @@ impl<T: WebDriverHandler<U>, U: WebDriverExtensionRoute> Dispatcher<T, U> {
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&mut self, msg_chan: Receiver<DispatchMessage<U>>) {
|
||||
fn run(&mut self, msg_chan: &Receiver<DispatchMessage<U>>) {
|
||||
loop {
|
||||
match msg_chan.recv() {
|
||||
Ok(DispatchMessage::HandleWebDriver(msg, resp_chan)) => {
|
||||
@ -190,7 +190,8 @@ impl<U: WebDriverExtensionRoute + 'static> Service for HttpHandler<U> {
|
||||
// The fact that this locks for basically the whole request doesn't
|
||||
// matter as long as we are only handling one request at a time.
|
||||
match api.lock() {
|
||||
Ok(ref api) => api.decode_request(method, &uri.path(), &body[..]),
|
||||
|
||||
Ok(ref api) => api.decode_request(&method, &uri.path(), &body[..]),
|
||||
Err(e) => panic!("Error decoding request: {:?}", e),
|
||||
}
|
||||
};
|
||||
@ -284,7 +285,7 @@ where
|
||||
let builder = thread::Builder::new().name("webdriver dispatcher".to_string());
|
||||
builder.spawn(move || {
|
||||
let mut dispatcher = Dispatcher::new(handler);
|
||||
dispatcher.run(msg_recv);
|
||||
dispatcher.run(&msg_recv);
|
||||
})?;
|
||||
|
||||
Ok(Listener { _guard: Some(handle), socket: addr })
|
||||
|
Loading…
Reference in New Issue
Block a user