Skip to content

Commit 7500307

Browse files
committed
Avoid unnecessary net_traits::LoadData clone.
1 parent 6509cde commit 7500307

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

components/net/http_loader.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ fn load_for_consumer(load_data: LoadData,
155155
};
156156

157157
let ui_provider = TFDProvider;
158-
let context = load_data.context.clone();
159-
match load(load_data, &ui_provider, &http_state,
158+
match load(&load_data, &ui_provider, &http_state,
160159
devtools_chan, &factory,
161160
user_agent, &cancel_listener) {
162161
Err(LoadError::UnsupportedScheme(url)) => {
@@ -180,14 +179,14 @@ fn load_for_consumer(load_data: LoadData,
180179

181180
let mut image = resources_dir_path();
182181
image.push("badcert.html");
183-
let load_data = LoadData::new(context, Url::from_file_path(&*image).unwrap(), None);
182+
let load_data = LoadData::new(load_data.context, Url::from_file_path(&*image).unwrap(), None);
184183

185184
file_loader::factory(load_data, start_chan, classifier, cancel_listener)
186185
}
187186
Err(LoadError::ConnectionAborted(_)) => unreachable!(),
188187
Ok(mut load_response) => {
189188
let metadata = load_response.metadata.clone();
190-
send_data(context, &mut load_response, start_chan, metadata, classifier, &cancel_listener)
189+
send_data(load_data.context, &mut load_response, start_chan, metadata, classifier, &cancel_listener)
191190
}
192191
}
193192
}
@@ -719,14 +718,14 @@ impl UIProvider for TFDProvider {
719718

720719
struct TFDProvider;
721720

722-
pub fn load<A, B>(load_data: LoadData,
723-
ui_provider: &B,
724-
http_state: &HttpState,
725-
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
726-
request_factory: &HttpRequestFactory<R=A>,
727-
user_agent: String,
728-
cancel_listener: &CancellationListener)
729-
-> Result<StreamedResponse<A::R>, LoadError> where A: HttpRequest + 'static, B: UIProvider {
721+
pub fn load<A, B>(load_data: &LoadData,
722+
ui_provider: &B,
723+
http_state: &HttpState,
724+
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
725+
request_factory: &HttpRequestFactory<R=A>,
726+
user_agent: String,
727+
cancel_listener: &CancellationListener)
728+
-> Result<StreamedResponse<A::R>, LoadError> where A: HttpRequest + 'static, B: UIProvider {
730729
let max_redirects = prefs::get_pref("network.http.redirection-limit").as_i64().unwrap() as u32;
731730
let mut iters = 0;
732731
// URL of the document being loaded, as seen by all the higher-level code.

tests/unit/net/http_loader.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ fn test_check_default_headers_loaded_in_every_request() {
346346
headers.set(UserAgent(DEFAULT_USER_AGENT.to_owned()));
347347

348348
// Testing for method.GET
349-
let _ = load(load_data.clone(), &ui_provider, &http_state, None,
349+
let _ = load(&load_data, &ui_provider, &http_state, None,
350350
&AssertMustHaveHeadersRequestFactory {
351351
expected_headers: headers.clone(),
352352
body: <[_]>::to_vec(&[])
@@ -357,7 +357,7 @@ fn test_check_default_headers_loaded_in_every_request() {
357357

358358
headers.set(ContentLength(0 as u64));
359359

360-
let _ = load(load_data.clone(), &ui_provider, &http_state, None,
360+
let _ = load(&load_data, &ui_provider, &http_state, None,
361361
&AssertMustHaveHeadersRequestFactory {
362362
expected_headers: headers,
363363
body: <[_]>::to_vec(&[])
@@ -379,7 +379,7 @@ fn test_load_when_request_is_not_get_or_head_and_there_is_no_body_content_length
379379
content_length.set(ContentLength(0));
380380

381381
let _ = load(
382-
load_data.clone(), &ui_provider, &http_state,
382+
&load_data, &ui_provider, &http_state,
383383
None, &AssertMustIncludeHeadersRequestFactory {
384384
expected_headers: content_length,
385385
body: <[_]>::to_vec(&[])
@@ -413,7 +413,7 @@ fn test_request_and_response_data_with_network_messages() {
413413
let mut request_headers = Headers::new();
414414
request_headers.set(Host { hostname: "bar.foo".to_owned(), port: None });
415415
load_data.headers = request_headers.clone();
416-
let _ = load(load_data, &ui_provider, &http_state, Some(devtools_chan), &Factory,
416+
let _ = load(&load_data, &ui_provider, &http_state, Some(devtools_chan), &Factory,
417417
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
418418

419419
// notification received from devtools
@@ -483,7 +483,7 @@ fn test_request_and_response_message_from_devtool_without_pipeline_id() {
483483
let url = Url::parse("https://mozilla.com").unwrap();
484484
let (devtools_chan, devtools_port) = mpsc::channel::<DevtoolsControlMsg>();
485485
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), None);
486-
let _ = load(load_data, &ui_provider, &http_state, Some(devtools_chan), &Factory,
486+
let _ = load(&load_data, &ui_provider, &http_state, Some(devtools_chan), &Factory,
487487
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
488488

489489
// notification received from devtools
@@ -517,7 +517,7 @@ fn test_load_when_redirecting_from_a_post_should_rewrite_next_request_as_get() {
517517
let http_state = HttpState::new();
518518
let ui_provider = TestProvider::new();
519519

520-
let _ = load(load_data, &ui_provider, &http_state, None, &Factory,
520+
let _ = load(&load_data, &ui_provider, &http_state, None, &Factory,
521521
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
522522
}
523523

@@ -546,7 +546,7 @@ fn test_load_should_decode_the_response_as_deflate_when_response_headers_have_co
546546
let ui_provider = TestProvider::new();
547547

548548
let mut response = load(
549-
load_data, &ui_provider, &http_state, None,
549+
&load_data, &ui_provider, &http_state, None,
550550
&Factory,
551551
DEFAULT_USER_AGENT.to_owned(),
552552
&CancellationListener::new(None))
@@ -579,7 +579,7 @@ fn test_load_should_decode_the_response_as_gzip_when_response_headers_have_conte
579579
let ui_provider = TestProvider::new();
580580

581581
let mut response = load(
582-
load_data,
582+
&load_data,
583583
&ui_provider, &http_state,
584584
None, &Factory,
585585
DEFAULT_USER_AGENT.to_owned(),
@@ -623,7 +623,7 @@ fn test_load_doesnt_send_request_body_on_any_redirect() {
623623
let ui_provider = TestProvider::new();
624624

625625
let _ = load(
626-
load_data, &ui_provider, &http_state,
626+
&load_data, &ui_provider, &http_state,
627627
None,
628628
&Factory,
629629
DEFAULT_USER_AGENT.to_owned(),
@@ -652,7 +652,7 @@ fn test_load_doesnt_add_host_to_sts_list_when_url_is_http_even_if_sts_headers_ar
652652
let http_state = HttpState::new();
653653
let ui_provider = TestProvider::new();
654654

655-
let _ = load(load_data,
655+
let _ = load(&load_data,
656656
&ui_provider, &http_state,
657657
None,
658658
&Factory,
@@ -684,7 +684,7 @@ fn test_load_adds_host_to_sts_list_when_url_is_https_and_sts_headers_are_present
684684
let http_state = HttpState::new();
685685
let ui_provider = TestProvider::new();
686686

687-
let _ = load(load_data,
687+
let _ = load(&load_data,
688688
&ui_provider, &http_state,
689689
None,
690690
&Factory,
@@ -718,7 +718,7 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_
718718

719719
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), None);
720720

721-
let _ = load(load_data,
721+
let _ = load(&load_data,
722722
&ui_provider, &http_state,
723723
None,
724724
&Factory,
@@ -752,7 +752,7 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re
752752
let mut cookie = Headers::new();
753753
cookie.set(CookieHeader(vec![CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned())]));
754754

755-
let _ = load(load_data.clone(), &ui_provider, &http_state, None,
755+
let _ = load(&load_data.clone(), &ui_provider, &http_state, None,
756756
&AssertMustIncludeHeadersRequestFactory {
757757
expected_headers: cookie,
758758
body: <[_]>::to_vec(&*load_data.data.unwrap())
@@ -795,7 +795,7 @@ fn test_load_sends_secure_cookie_if_http_changed_to_https_due_to_entry_in_hsts_s
795795
headers.set_raw("Cookie".to_owned(), vec![<[_]>::to_vec("mozillaIs=theBest".as_bytes())]);
796796

797797
let _ = load(
798-
load_data.clone(), &ui_provider, &http_state, None,
798+
&load_data.clone(), &ui_provider, &http_state, None,
799799
&AssertMustIncludeHeadersRequestFactory {
800800
expected_headers: headers,
801801
body: <[_]>::to_vec(&*load_data.data.unwrap())
@@ -827,7 +827,7 @@ fn test_load_sends_cookie_if_nonhttp() {
827827
headers.set_raw("Cookie".to_owned(), vec![<[_]>::to_vec("mozillaIs=theBest".as_bytes())]);
828828

829829
let _ = load(
830-
load_data.clone(), &ui_provider, &http_state, None,
830+
&load_data.clone(), &ui_provider, &http_state, None,
831831
&AssertMustIncludeHeadersRequestFactory {
832832
expected_headers: headers,
833833
body: <[_]>::to_vec(&*load_data.data.unwrap())
@@ -855,7 +855,7 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(
855855
let ui_provider = TestProvider::new();
856856

857857
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), None);
858-
let _ = load(load_data,
858+
let _ = load(&load_data,
859859
&ui_provider, &http_state,
860860
None,
861861
&Factory,
@@ -885,7 +885,7 @@ fn test_when_cookie_received_marked_secure_is_ignored_for_http() {
885885
let ui_provider = TestProvider::new();
886886

887887
let load_data = LoadData::new(LoadContext::Browsing, Url::parse("http://mozilla.com").unwrap(), None);
888-
let _ = load(load_data,
888+
let _ = load(&load_data,
889889
&ui_provider, &http_state,
890890
None,
891891
&Factory,
@@ -921,7 +921,7 @@ fn test_when_cookie_set_marked_httpsonly_secure_isnt_sent_on_http_request() {
921921
assert_cookie_for_domain(http_state.cookie_jar.clone(), "https://mozilla.com", "mozillaIs=theBest");
922922

923923
let _ = load(
924-
load_data.clone(), &ui_provider, &http_state, None,
924+
&load_data.clone(), &ui_provider, &http_state, None,
925925
&AssertMustNotIncludeHeadersRequestFactory {
926926
headers_not_expected: vec!["Cookie".to_owned()],
927927
body: <[_]>::to_vec(&*load_data.data.unwrap())
@@ -942,7 +942,7 @@ fn test_load_sets_content_length_to_length_of_request_body() {
942942
let http_state = HttpState::new();
943943
let ui_provider = TestProvider::new();
944944

945-
let _ = load(load_data.clone(), &ui_provider, &http_state,
945+
let _ = load(&load_data.clone(), &ui_provider, &http_state,
946946
None, &AssertMustIncludeHeadersRequestFactory {
947947
expected_headers: content_len_headers,
948948
body: <[_]>::to_vec(&*load_data.data.unwrap())
@@ -965,7 +965,7 @@ fn test_load_uses_explicit_accept_from_headers_in_load_data() {
965965
let http_state = HttpState::new();
966966
let ui_provider = TestProvider::new();
967967

968-
let _ = load(load_data,
968+
let _ = load(&load_data,
969969
&ui_provider, &http_state,
970970
None,
971971
&AssertMustIncludeHeadersRequestFactory {
@@ -992,7 +992,7 @@ fn test_load_sets_default_accept_to_html_xhtml_xml_and_then_anything_else() {
992992
let http_state = HttpState::new();
993993
let ui_provider = TestProvider::new();
994994

995-
let _ = load(load_data,
995+
let _ = load(&load_data,
996996
&ui_provider, &http_state,
997997
None,
998998
&AssertMustIncludeHeadersRequestFactory {
@@ -1015,7 +1015,7 @@ fn test_load_uses_explicit_accept_encoding_from_load_data_headers() {
10151015
let http_state = HttpState::new();
10161016
let ui_provider = TestProvider::new();
10171017

1018-
let _ = load(load_data,
1018+
let _ = load(&load_data,
10191019
&ui_provider, &http_state,
10201020
None,
10211021
&AssertMustIncludeHeadersRequestFactory {
@@ -1039,7 +1039,7 @@ fn test_load_sets_default_accept_encoding_to_gzip_and_deflate() {
10391039
let http_state = HttpState::new();
10401040
let ui_provider = TestProvider::new();
10411041

1042-
let _ = load(load_data,
1042+
let _ = load(&load_data,
10431043
&ui_provider, &http_state,
10441044
None,
10451045
&AssertMustIncludeHeadersRequestFactory {
@@ -1073,7 +1073,7 @@ fn test_load_errors_when_there_a_redirect_loop() {
10731073
let http_state = HttpState::new();
10741074
let ui_provider = TestProvider::new();
10751075

1076-
match load(load_data, &ui_provider, &http_state, None, &Factory,
1076+
match load(&load_data, &ui_provider, &http_state, None, &Factory,
10771077
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
10781078
Err(LoadError::InvalidRedirect(_, msg)) => {
10791079
assert_eq!(msg, "redirect loop");
@@ -1108,7 +1108,7 @@ fn test_load_errors_when_there_is_too_many_redirects() {
11081108
prefs::set_pref("network.http.redirection-limit",
11091109
prefs::PrefValue::Number(redirect_limit));
11101110

1111-
match load(load_data, &ui_provider, &http_state, None, &Factory,
1111+
match load(&load_data, &ui_provider, &http_state, None, &Factory,
11121112
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
11131113
Err(LoadError::MaxRedirects(url, num_redirects)) => {
11141114
assert_eq!(num_redirects, redirect_limit as u32);
@@ -1150,7 +1150,7 @@ fn test_load_follows_a_redirect() {
11501150
let http_state = HttpState::new();
11511151
let ui_provider = TestProvider::new();
11521152

1153-
match load(load_data, &ui_provider, &http_state, None, &Factory,
1153+
match load(&load_data, &ui_provider, &http_state, None, &Factory,
11541154
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
11551155
Err(e) => panic!("expected to follow a redirect {:?}", e),
11561156
Ok(mut lr) => {
@@ -1178,7 +1178,7 @@ fn test_load_errors_when_scheme_is_not_http_or_https() {
11781178
let http_state = HttpState::new();
11791179
let ui_provider = TestProvider::new();
11801180

1181-
match load(load_data,
1181+
match load(&load_data,
11821182
&ui_provider, &http_state,
11831183
None,
11841184
&DontConnectFactory,
@@ -1197,7 +1197,7 @@ fn test_load_errors_when_viewing_source_and_inner_url_scheme_is_not_http_or_http
11971197
let http_state = HttpState::new();
11981198
let ui_provider = TestProvider::new();
11991199

1200-
match load(load_data,
1200+
match load(&load_data,
12011201
&ui_provider, &http_state,
12021202
None,
12031203
&DontConnectFactory,
@@ -1239,7 +1239,7 @@ fn test_load_errors_when_cancelled() {
12391239
let http_state = HttpState::new();
12401240
let ui_provider = TestProvider::new();
12411241

1242-
match load(load_data,
1242+
match load(&load_data,
12431243
&ui_provider, &http_state,
12441244
None,
12451245
&Factory,
@@ -1309,7 +1309,7 @@ fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
13091309
cookie_jar.push(cookie_y, CookieSource::HTTP);
13101310
}
13111311

1312-
match load(load_data,
1312+
match load(&load_data,
13131313
&ui_provider, &http_state,
13141314
None,
13151315
&Factory,
@@ -1355,7 +1355,7 @@ fn test_redirect_from_x_to_x_provides_x_with_cookie_from_first_response() {
13551355
let http_state = HttpState::new();
13561356
let ui_provider = TestProvider::new();
13571357

1358-
match load(load_data,
1358+
match load(&load_data,
13591359
&ui_provider, &http_state,
13601360
None,
13611361
&Factory,
@@ -1398,7 +1398,7 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
13981398
);
13991399

14001400
let _ = load(
1401-
load_data.clone(), &ui_provider, &http_state,
1401+
&load_data, &ui_provider, &http_state,
14021402
None, &AssertMustIncludeHeadersRequestFactory {
14031403
expected_headers: auth_header,
14041404
body: <[_]>::to_vec(&[])
@@ -1425,7 +1425,7 @@ fn test_auth_ui_sets_header_on_401() {
14251425
let load_data = LoadData::new(LoadContext::Browsing, url, None);
14261426

14271427
match load(
1428-
load_data.clone(), &ui_provider, &http_state,
1428+
&load_data, &ui_provider, &http_state,
14291429
None, &AssertAuthHeaderRequestFactory {
14301430
expected_headers: auth_header,
14311431
body: <[_]>::to_vec(&[])

0 commit comments

Comments
 (0)