This commit is contained in:
Simon Gardling 2022-05-16 17:26:41 -04:00
parent 6d06c25fac
commit 5cf736cf78
4 changed files with 17 additions and 7 deletions

View File

@ -32,9 +32,9 @@ fi
mkdir tmp mkdir tmp
cp -r pkg/ytbn_graphing_software_bg.wasm tmp/ cp -r pkg/ytbn_graphing_software_bg.wasm tmp/
# sed -i 's/fatal: true/fatal: false/g' pkg/ytbn_graphing_software.js sed -i 's/fatal: true/fatal: false/g' pkg/ytbn_graphing_software.js
# sed -i "s/TextEncoder('utf-8')/TextEncoder('utf-8', { ignoreBOM: true, fatal: false })/g" pkg/ytbn_graphing_software.js sed -i "s/TextEncoder('utf-8')/TextEncoder('utf-8', { ignoreBOM: true, fatal: false })/g" pkg/ytbn_graphing_software.js
minify pkg/ytbn_graphing_software.js > tmp/ytbn_graphing_software.js minify pkg/ytbn_graphing_software.js > tmp/ytbn_graphing_software.js

View File

@ -9,7 +9,7 @@
#![feature(const_assume)] #![feature(const_assume)]
#![feature(const_option_ext)] #![feature(const_option_ext)]
#![feature(const_slice_index)] #![feature(const_slice_index)]
#![feature(split_array)] #![feature(slice_split_at_unchecked)]
#[macro_use] #[macro_use]
extern crate static_assertions; extern crate static_assertions;

View File

@ -9,7 +9,7 @@
#![feature(const_assume)] #![feature(const_assume)]
#![feature(const_option_ext)] #![feature(const_option_ext)]
#![feature(const_slice_index)] #![feature(const_slice_index)]
#![feature(split_array)] #![feature(slice_split_at_unchecked)]
#[macro_use] #[macro_use]
extern crate static_assertions; extern crate static_assertions;

View File

@ -309,9 +309,10 @@ pub fn almost_variable(x: f64) -> Option<char> {
} }
pub const HASH_LENGTH: usize = 8; pub const HASH_LENGTH: usize = 8;
type CommitBits = [u8; HASH_LENGTH];
#[allow(dead_code)] #[allow(dead_code)]
pub fn hashed_storage_create(hash: [u8; HASH_LENGTH], data: &[u8]) -> String { pub fn hashed_storage_create(hash: CommitBits, data: &[u8]) -> String {
// cannot use `from_utf8` seems to break on wasm. no clue why // cannot use `from_utf8` seems to break on wasm. no clue why
[&hash, data] [&hash, data]
.concat() .concat()
@ -321,15 +322,24 @@ pub fn hashed_storage_create(hash: [u8; HASH_LENGTH], data: &[u8]) -> String {
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn hashed_storage_read(data: String) -> Option<([u8; HASH_LENGTH], Vec<u8>)> { pub fn hashed_storage_read(data: String) -> Option<(CommitBits, Vec<u8>)> {
if HASH_LENGTH >= data.len() { if HASH_LENGTH >= data.len() {
return None; return None;
} }
unsafe {
assume(!data.is_empty());
assume(data.len() > HASH_LENGTH);
}
// can't use data.as_bytes() here for some reason, seems to break on wasm? // can't use data.as_bytes() here for some reason, seems to break on wasm?
let decoded_1 = data.chars().map(|c| c as u8).collect::<Vec<u8>>(); let decoded_1 = data.chars().map(|c| c as u8).collect::<Vec<u8>>();
let (hash, cached_data) = decoded_1.split_array_ref::<HASH_LENGTH>(); let (hash, cached_data) = {
let (a, b) = unsafe { decoded_1.split_at_unchecked(HASH_LENGTH) };
unsafe { (&*(a.as_ptr() as *const CommitBits), b) }
};
debug_assert!(!cached_data.is_empty()); debug_assert!(!cached_data.is_empty());
Some((*hash, cached_data.to_vec())) Some((*hash, cached_data.to_vec()))