Skip to content

Commit

Permalink
Deserializing now borrows symbols appropriately
Browse files Browse the repository at this point in the history
I noticed that SymbolMap::new() returned an Owned map, which prevented
the cheaper option of borrowing when possible. I updated both from_slice
and from_read, but the from_read path can't actually call the borrow
push function due to not being able to borrow.

I also noticed that tuple serialization wasn't tested, although enum
tuples were.
  • Loading branch information
ecton committed Jul 30, 2023
1 parent 0d0f36f commit 83a9af1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pot/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ impl<'s, 'de> Deserializer<'s, 'de, SliceReader<'de>> {
/// Returns a new deserializer for `input`.
#[inline]
pub(crate) fn from_slice(input: &'de [u8], maximum_bytes_allocatable: usize) -> Result<Self> {
Self::from_slice_with_symbols(input, SymbolMap::new(), maximum_bytes_allocatable)
Self::from_slice_with_symbols(
input,
SymbolMap::Borrowed(SymbolList::new()),
maximum_bytes_allocatable,
)
}

fn from_slice_with_symbols(
Expand All @@ -64,7 +68,7 @@ impl<'s, 'de, R: ReadBytesExt> Deserializer<'s, 'de, IoReader<R>> {
pub(crate) fn from_read(input: R, maximum_bytes_allocatable: usize) -> Result<Self> {
Self::new(
IoReader::new(input),
SymbolMap::new(),
SymbolMap::Borrowed(SymbolList::new()),
maximum_bytes_allocatable,
)
}
Expand Down
5 changes: 5 additions & 0 deletions pot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ mod tests {
test_serialization(&0.1_f32, Some(5));
}

#[test]
fn tuples() {
test_serialization(&(1, true, 3), None);
}

#[test]
fn enums() {
test_serialization(&EnumVariants::Unit, None);
Expand Down

0 comments on commit 83a9af1

Please sign in to comment.