Delete Decoder::read_seq
This commit is contained in:
parent
75614c06ee
commit
42904b0219
3 changed files with 54 additions and 64 deletions
|
@ -130,16 +130,16 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
|
||||||
let _i: SerializedDepNodeIndex = fingerprints.push(fingerprint);
|
let _i: SerializedDepNodeIndex = fingerprints.push(fingerprint);
|
||||||
debug_assert_eq!(_i.index(), _index);
|
debug_assert_eq!(_i.index(), _index);
|
||||||
|
|
||||||
d.read_seq(|d, len| {
|
// Deserialize edges -- sequence of DepNodeIndex
|
||||||
let start = edge_list_data.len().try_into().unwrap();
|
let len = d.read_usize();
|
||||||
for _ in 0..len {
|
let start = edge_list_data.len().try_into().unwrap();
|
||||||
let edge = Decodable::decode(d);
|
for _ in 0..len {
|
||||||
edge_list_data.push(edge);
|
let edge = Decodable::decode(d);
|
||||||
}
|
edge_list_data.push(edge);
|
||||||
let end = edge_list_data.len().try_into().unwrap();
|
}
|
||||||
let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
|
let end = edge_list_data.len().try_into().unwrap();
|
||||||
debug_assert_eq!(_i.index(), _index);
|
let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
|
||||||
})
|
debug_assert_eq!(_i.index(), _index);
|
||||||
}
|
}
|
||||||
|
|
||||||
let index: FxHashMap<_, _> =
|
let index: FxHashMap<_, _> =
|
||||||
|
|
|
@ -18,7 +18,8 @@ impl<S: Encoder, A: Array<Item: Encodable<S>>> Encodable<S> for SmallVec<A> {
|
||||||
|
|
||||||
impl<D: Decoder, A: Array<Item: Decodable<D>>> Decodable<D> for SmallVec<A> {
|
impl<D: Decoder, A: Array<Item: Decodable<D>>> Decodable<D> for SmallVec<A> {
|
||||||
fn decode(d: &mut D) -> SmallVec<A> {
|
fn decode(d: &mut D) -> SmallVec<A> {
|
||||||
d.read_seq(|d, len| (0..len).map(|_| Decodable::decode(d)).collect())
|
let len = d.read_usize();
|
||||||
|
(0..len).map(|_| Decodable::decode(d)).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +36,8 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for LinkedList<T> {
|
||||||
|
|
||||||
impl<D: Decoder, T: Decodable<D>> Decodable<D> for LinkedList<T> {
|
impl<D: Decoder, T: Decodable<D>> Decodable<D> for LinkedList<T> {
|
||||||
fn decode(d: &mut D) -> LinkedList<T> {
|
fn decode(d: &mut D) -> LinkedList<T> {
|
||||||
d.read_seq(|d, len| (0..len).map(|_| Decodable::decode(d)).collect())
|
let len = d.read_usize();
|
||||||
|
(0..len).map(|_| Decodable::decode(d)).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +54,8 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for VecDeque<T> {
|
||||||
|
|
||||||
impl<D: Decoder, T: Decodable<D>> Decodable<D> for VecDeque<T> {
|
impl<D: Decoder, T: Decodable<D>> Decodable<D> for VecDeque<T> {
|
||||||
fn decode(d: &mut D) -> VecDeque<T> {
|
fn decode(d: &mut D) -> VecDeque<T> {
|
||||||
d.read_seq(|d, len| (0..len).map(|_| Decodable::decode(d)).collect())
|
let len = d.read_usize();
|
||||||
|
(0..len).map(|_| Decodable::decode(d)).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,13 +112,12 @@ where
|
||||||
T: Decodable<D> + PartialEq + Ord,
|
T: Decodable<D> + PartialEq + Ord,
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> BTreeSet<T> {
|
fn decode(d: &mut D) -> BTreeSet<T> {
|
||||||
d.read_seq(|d, len| {
|
let len = d.read_usize();
|
||||||
let mut set = BTreeSet::new();
|
let mut set = BTreeSet::new();
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
set.insert(Decodable::decode(d));
|
set.insert(Decodable::decode(d));
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,14 +189,13 @@ where
|
||||||
S: BuildHasher + Default,
|
S: BuildHasher + Default,
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> HashSet<T, S> {
|
fn decode(d: &mut D) -> HashSet<T, S> {
|
||||||
d.read_seq(|d, len| {
|
let len = d.read_usize();
|
||||||
let state = Default::default();
|
let state = Default::default();
|
||||||
let mut set = HashSet::with_capacity_and_hasher(len, state);
|
let mut set = HashSet::with_capacity_and_hasher(len, state);
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
set.insert(Decodable::decode(d));
|
set.insert(Decodable::decode(d));
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,14 +257,13 @@ where
|
||||||
S: BuildHasher + Default,
|
S: BuildHasher + Default,
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> indexmap::IndexSet<T, S> {
|
fn decode(d: &mut D) -> indexmap::IndexSet<T, S> {
|
||||||
d.read_seq(|d, len| {
|
let len = d.read_usize();
|
||||||
let state = Default::default();
|
let state = Default::default();
|
||||||
let mut set = indexmap::IndexSet::with_capacity_and_hasher(len, state);
|
let mut set = indexmap::IndexSet::with_capacity_and_hasher(len, state);
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
set.insert(Decodable::decode(d));
|
set.insert(Decodable::decode(d));
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,14 +201,6 @@ pub trait Decoder {
|
||||||
fn read_str(&mut self) -> Cow<'_, str>;
|
fn read_str(&mut self) -> Cow<'_, str>;
|
||||||
fn read_raw_bytes_into(&mut self, s: &mut [u8]);
|
fn read_raw_bytes_into(&mut self, s: &mut [u8]);
|
||||||
|
|
||||||
fn read_seq<T, F>(&mut self, f: F) -> T
|
|
||||||
where
|
|
||||||
F: FnOnce(&mut Self, usize) -> T,
|
|
||||||
{
|
|
||||||
let len = self.read_usize();
|
|
||||||
f(self, len)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_map<T, F>(&mut self, f: F) -> T
|
fn read_map<T, F>(&mut self, f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self, usize) -> T,
|
F: FnOnce(&mut Self, usize) -> T,
|
||||||
|
@ -397,19 +389,18 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for Vec<T> {
|
||||||
|
|
||||||
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> {
|
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> {
|
||||||
default fn decode(d: &mut D) -> Vec<T> {
|
default fn decode(d: &mut D) -> Vec<T> {
|
||||||
d.read_seq(|d, len| {
|
let len = d.read_usize();
|
||||||
// SAFETY: we set the capacity in advance, only write elements, and
|
// SAFETY: we set the capacity in advance, only write elements, and
|
||||||
// only set the length at the end once the writing has succeeded.
|
// only set the length at the end once the writing has succeeded.
|
||||||
let mut vec = Vec::with_capacity(len);
|
let mut vec = Vec::with_capacity(len);
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut T = vec.as_mut_ptr();
|
let ptr: *mut T = vec.as_mut_ptr();
|
||||||
for i in 0..len {
|
for i in 0..len {
|
||||||
std::ptr::write(ptr.offset(i as isize), Decodable::decode(d));
|
std::ptr::write(ptr.offset(i as isize), Decodable::decode(d));
|
||||||
}
|
|
||||||
vec.set_len(len);
|
|
||||||
}
|
}
|
||||||
vec
|
vec.set_len(len);
|
||||||
})
|
}
|
||||||
|
vec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,14 +413,13 @@ impl<S: Encoder, T: Encodable<S>, const N: usize> Encodable<S> for [T; N] {
|
||||||
|
|
||||||
impl<D: Decoder, const N: usize> Decodable<D> for [u8; N] {
|
impl<D: Decoder, const N: usize> Decodable<D> for [u8; N] {
|
||||||
fn decode(d: &mut D) -> [u8; N] {
|
fn decode(d: &mut D) -> [u8; N] {
|
||||||
d.read_seq(|d, len| {
|
let len = d.read_usize();
|
||||||
assert!(len == N);
|
assert!(len == N);
|
||||||
let mut v = [0u8; N];
|
let mut v = [0u8; N];
|
||||||
for i in 0..len {
|
for i in 0..len {
|
||||||
v[i] = Decodable::decode(d);
|
v[i] = Decodable::decode(d);
|
||||||
}
|
}
|
||||||
v
|
v
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue