This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Dr-Emann/libretro
Massive save state speedup
- Loading branch information
Showing
6 changed files
with
89 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::{mem, slice}; | ||
use serde_bytes::ByteBuf; | ||
use serde::{Serializer, Deserializer, Deserialize}; | ||
|
||
pub fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error> | ||
where T: From<Vec<i8>>, | ||
D: Deserializer<'de> | ||
{ | ||
ByteBuf::deserialize(deserializer).map(|buf| { | ||
let mut u8_v: Vec<u8> = buf.into(); | ||
|
||
let i8_v = unsafe { | ||
Vec::from_raw_parts( | ||
u8_v.as_mut_ptr() as *mut i8, | ||
u8_v.len(), | ||
u8_v.capacity() | ||
) | ||
}; | ||
mem::forget(u8_v); | ||
i8_v.into() | ||
}) | ||
} | ||
|
||
pub fn serialize<T, S>(bytes: &T, serializer: S) -> Result<S::Ok, S::Error> | ||
where T: ?Sized + AsRef<[i8]>, | ||
S: Serializer | ||
{ | ||
let i8_s: &[i8] = bytes.as_ref(); | ||
let u8_s: &[u8] = unsafe { slice::from_raw_parts(i8_s.as_ptr() as *const u8, i8_s.len()) }; | ||
serializer.serialize_bytes(u8_s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters