optimize SHORT_COMMIT to bytes
This commit is contained in:
@@ -155,7 +155,7 @@ impl MathApp {
|
|||||||
assume(!cached_data.is_empty());
|
assume(!cached_data.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
if commit == build::SHORT_COMMIT.chars().map(|c| c as u8).collect::<Vec<u8>>().as_slice() {
|
if commit == const { unsafe { std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT) } } {
|
||||||
tracing::info!("Reading decompression cache. Bytes: {}", cached_data.len());
|
tracing::info!("Reading decompression cache. Bytes: {}", cached_data.len());
|
||||||
return Some(cached_data.to_vec());
|
return Some(cached_data.to_vec());
|
||||||
} else {
|
} else {
|
||||||
@@ -171,7 +171,7 @@ impl MathApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tracing::info!("Setting decompression cache");
|
tracing::info!("Setting decompression cache");
|
||||||
let commit: [u8; crate::misc::HASH_LENGTH] = unsafe { build::SHORT_COMMIT.as_bytes().try_into().unwrap_unchecked() };
|
let commit: crate::misc::HashBytes = const { unsafe { std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT) } };
|
||||||
let saved_data = &crate::misc::hashed_storage_create(commit, data);
|
let saved_data = &crate::misc::hashed_storage_create(commit, data);
|
||||||
tracing::info!("Bytes: {}", saved_data.len());
|
tracing::info!("Bytes: {}", saved_data.len());
|
||||||
get_localstorage().set_item(DATA_NAME, saved_data).expect("failed to set local storage cache");
|
get_localstorage().set_item(DATA_NAME, saved_data).expect("failed to set local storage cache");
|
||||||
@@ -193,7 +193,7 @@ impl MathApp {
|
|||||||
assume(!func_data.is_empty());
|
assume(!func_data.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
if commit == unsafe { std::mem::transmute::<&str, &[u8]>(build::SHORT_COMMIT) } {
|
if commit == const { unsafe { std::mem::transmute::<&str, &[u8]>(build::SHORT_COMMIT) } } {
|
||||||
tracing::info!("Reading previous function data");
|
tracing::info!("Reading previous function data");
|
||||||
let function_manager: FunctionManager = bincode::deserialize(&func_data).ok()?;
|
let function_manager: FunctionManager = bincode::deserialize(&func_data).ok()?;
|
||||||
return Some(function_manager);
|
return Some(function_manager);
|
||||||
@@ -209,7 +209,9 @@ impl MathApp {
|
|||||||
let mut data = Vec::new();
|
let mut data = Vec::new();
|
||||||
let _ = unsafe {
|
let _ = unsafe {
|
||||||
ruzstd::StreamingDecoder::new(
|
ruzstd::StreamingDecoder::new(
|
||||||
&mut include_bytes!(concat!(env!("OUT_DIR"), "/compressed_data")).as_slice(),
|
&mut const {
|
||||||
|
include_bytes!(concat!(env!("OUT_DIR"), "/compressed_data")).as_slice()
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.unwrap_unchecked()
|
.unwrap_unchecked()
|
||||||
.read_to_end(&mut data)
|
.read_to_end(&mut data)
|
||||||
@@ -623,16 +625,11 @@ impl App for MathApp {
|
|||||||
.local_storage()
|
.local_storage()
|
||||||
{
|
{
|
||||||
tracing::info!("Setting current functions");
|
tracing::info!("Setting current functions");
|
||||||
|
let hash: crate::misc::HashBytes = unsafe {
|
||||||
|
std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT)
|
||||||
|
};
|
||||||
let saved_data = &crate::misc::hashed_storage_create(
|
let saved_data = &crate::misc::hashed_storage_create(
|
||||||
unsafe {
|
hash,
|
||||||
build::SHORT_COMMIT
|
|
||||||
.chars()
|
|
||||||
.map(|c| c as u8)
|
|
||||||
.collect::<Vec<u8>>()
|
|
||||||
.as_slice()
|
|
||||||
.try_into()
|
|
||||||
.unwrap_unchecked()
|
|
||||||
},
|
|
||||||
bincode::serialize(&self.functions).unwrap().as_slice(),
|
bincode::serialize(&self.functions).unwrap().as_slice(),
|
||||||
);
|
);
|
||||||
// tracing::info!("Bytes: {}", saved_data.len());
|
// tracing::info!("Bytes: {}", saved_data.len());
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ pub fn almost_variable(x: f64) -> Option<char> {
|
|||||||
pub const HASH_LENGTH: usize = 8;
|
pub const HASH_LENGTH: usize = 8;
|
||||||
|
|
||||||
/// Represents bytes used to represent hash info
|
/// Represents bytes used to represent hash info
|
||||||
type HashBytes = [u8; HASH_LENGTH];
|
pub type HashBytes = [u8; HASH_LENGTH];
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn hashed_storage_create(hash: HashBytes, data: &[u8]) -> String {
|
pub fn hashed_storage_create(hash: HashBytes, data: &[u8]) -> String {
|
||||||
|
|||||||
Reference in New Issue
Block a user