Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add faster serde serialization, sacrificing invariant-safety for speed in release mode; test that it roudtrips #252

Closed
wants to merge 4 commits into from
Prev

Rename to serialize_unsafe

  • Loading branch information
Manishearth committed Dec 18, 2016
commit 70a816aeb1b1b57a0e58856a7f76399154b52287
@@ -1513,7 +1513,7 @@ impl rustc_serialize::Decodable for Url {
#[cfg(feature="serde")]
impl Url {
/// Serialize the URL efficiently, for use with IPC
pub fn serialize_efficient<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: serde::Serializer {
pub fn serialize_unsafe<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: serde::Serializer {
use serde::Serialize;
// Destructuring first lets us ensure that adding or removing fields forces this method
// to be updated
@@ -1529,11 +1529,11 @@ impl Url {

/// Deserialize the URL efficiently, without re-parsing
///
/// Deserializer must be known to contain the output of serialize_efficient
/// Deserializer must be known to contain the output of serialize_unsafe
///
/// Cannot cause memory unsafety if used incorrectly, but may cause security issues.
/// Only use with trusted input.
pub fn deserialize_efficient<D>(deserializer: &mut D)
pub fn deserialize_unsafe<D>(deserializer: &mut D)
-> Result<Url, D::Error>
where D: serde::Deserializer {
use serde::{Deserialize, Error};
@@ -1552,7 +1552,7 @@ impl Url {
query_start: query_start,
fragment_start: fragment_start
};
#[cfg(debug_assertions)] {
if cfg!(debug_assertions) {
if let Err(s) = url.assert_invariants_result() {
return Err(Error::invalid_value(&s))
}
@@ -26,11 +26,11 @@ fn assert_invariants(url: &Url) {
let mut write = Vec::<u8>::new();
{
let mut serializer = Serializer::new(&mut write);
url.serialize_efficient(&mut serializer).unwrap();
url.serialize_unsafe(&mut serializer).unwrap();
}
let mut read = &*write;
let mut deserializer = Deserializer::new(&mut read, SizeLimit::Infinite);
let new_url = Url::deserialize_efficient(&mut deserializer).unwrap();
let new_url = Url::deserialize_unsafe(&mut deserializer).unwrap();
assert_eq!(url, &new_url);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.