Skip to content
Snippets Groups Projects
Commit dc2b67f6 authored by Moritz Langenstein's avatar Moritz Langenstein
Browse files

(ml5717) Small improvements to release code compilation

parent c8d9e04f
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ edition = "2018" ...@@ -8,7 +8,7 @@ edition = "2018"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]
[features] [features]
default = ["console_error_panic_hook"] default = []
[dependencies] [dependencies]
wasm-bindgen = "0.2" wasm-bindgen = "0.2"
...@@ -22,13 +22,7 @@ bincode = "1.2.1" ...@@ -22,13 +22,7 @@ bincode = "1.2.1"
fixedbitset = "0.2.0" fixedbitset = "0.2.0"
ordered-float = { version = "1.0.2", features = ["serde"] } ordered-float = { version = "1.0.2", features = ["serde"] }
twox-hash = "1.1.1" twox-hash = "1.1.1"
web-sys = { version = "0.3.33", features = ["console"] } # web-sys = { version = "0.3.33", features = ["console"] }
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.1", optional = true }
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size # `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default # compared to the default allocator's ~10K. It is slower than the default
...@@ -43,3 +37,4 @@ wasm-bindgen-test = "0.2" ...@@ -43,3 +37,4 @@ wasm-bindgen-test = "0.2"
[profile.release] [profile.release]
opt-level = 3 opt-level = 3
lto = true lto = true
# panic = "abort"
No preview for this file type
#![feature(type_ascription)] #![feature(type_ascription)]
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use js_sys::Error; use js_sys::Error;
...@@ -10,12 +14,6 @@ use std::ops::Deref; ...@@ -10,12 +14,6 @@ use std::ops::Deref;
use std::option::Option; use std::option::Option;
use vec_map::VecMap; use vec_map::VecMap;
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
mod utils;
mod crdt; mod crdt;
use crdt::{DeltaVec, EventListener, IntervalUnion, Point, CRDT}; use crdt::{DeltaVec, EventListener, IntervalUnion, Point, CRDT};
...@@ -151,7 +149,20 @@ impl WasmCRDT { ...@@ -151,7 +149,20 @@ impl WasmCRDT {
pub fn apply_deltas(&mut self, deltas: Box<[u8]>) -> Result<bool, JsValue> { pub fn apply_deltas(&mut self, deltas: Box<[u8]>) -> Result<bool, JsValue> {
let deltas = match bincode::deserialize(&packing::unpack(&deltas)) { let deltas = match bincode::deserialize(&packing::unpack(&deltas)) {
Ok(deltas) => deltas, Ok(deltas) => deltas,
Err(error) => return Err(Error::new(&format!("{:?}", error)).into()), #[allow(unused_variables)]
Err(error) => {
return Err(Error::new({
#[cfg(debug_assertions)]
{
&format!("{:?}", error)
}
#[cfg(not(debug_assertions))]
{
"apply_deltas deltas deserialise error"
}
})
.into())
}
}; };
Ok(self.0.apply_deltas(deltas)) Ok(self.0.apply_deltas(deltas))
...@@ -168,7 +179,20 @@ impl WasmCRDT { ...@@ -168,7 +179,20 @@ impl WasmCRDT {
) -> Result<(), JsValue> { ) -> Result<(), JsValue> {
let remote_state = match bincode::deserialize(&packing::unpack(&remote_state)) { let remote_state = match bincode::deserialize(&packing::unpack(&remote_state)) {
Ok(remote_state) => remote_state, Ok(remote_state) => remote_state,
Err(error) => return Err(Error::new(&format!("{:?}", error)).into()), #[allow(unused_variables)]
Err(error) => {
return Err(Error::new({
#[cfg(debug_assertions)]
{
&format!("{:?}", error)
}
#[cfg(not(debug_assertions))]
{
"fetch_deltas_from_state_vector state deserialise error"
}
})
.into())
}
}; };
Ok(self.0.fetch_deltas_from_state_vector(user, &remote_state)) Ok(self.0.fetch_deltas_from_state_vector(user, &remote_state))
......
#[allow(dead_code)]
pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment