Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of String and Vec<u8> #58

Merged
merged 19 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
16 changes: 8 additions & 8 deletions borsh-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion borsh-rs/borsh-derive-internal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "borsh-derive-internal"
version = "0.5.0"
version = "0.6.0"
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions borsh-rs/borsh-derive-internal/src/enum_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn enum_de(input: &ItemEnum) -> syn::Result<TokenStream2> {
if let Some(method_ident) = init_method {
Ok(quote! {
impl #generics borsh::de::BorshDeserialize for #name #generics where #deserializable_field_types {
fn deserialize<R: std::io::Read>(reader: &mut R) -> std::result::Result<Self, std::io::Error> {
fn deserialize<R: std::io::BufRead>(reader: &mut R) -> std::result::Result<Self, std::io::Error> {
#variant_idx
let mut return_value = match variant_idx {
#variant_arms
Expand All @@ -82,7 +82,7 @@ pub fn enum_de(input: &ItemEnum) -> syn::Result<TokenStream2> {
} else {
Ok(quote! {
impl #generics borsh::de::BorshDeserialize for #name #generics where #deserializable_field_types {
fn deserialize<R: std::io::Read>(reader: &mut R) -> std::result::Result<Self, std::io::Error> {
fn deserialize<R: std::io::BufRead>(reader: &mut R) -> std::result::Result<Self, std::io::Error> {
#variant_idx
let return_value = match variant_idx {
#variant_arms
Expand Down
4 changes: 2 additions & 2 deletions borsh-rs/borsh-derive-internal/src/struct_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn struct_de(input: &ItemStruct) -> syn::Result<TokenStream2> {
if let Some(method_ident) = init_method {
Ok(quote! {
impl #generics borsh::de::BorshDeserialize for #name #generics where #deserializable_field_types {
fn deserialize<R: std::io::Read>(reader: &mut R) -> std::result::Result<Self, std::io::Error> {
fn deserialize<R: std::io::BufRead>(reader: &mut R) -> std::result::Result<Self, std::io::Error> {
let mut return_value = #return_value;
return_value.#method_ident();
Ok(return_value)
Expand All @@ -64,7 +64,7 @@ pub fn struct_de(input: &ItemStruct) -> syn::Result<TokenStream2> {
} else {
Ok(quote! {
impl #generics borsh::de::BorshDeserialize for #name #generics where #deserializable_field_types {
fn deserialize<R: std::io::Read>(reader: &mut R) -> std::result::Result<Self, std::io::Error> {
fn deserialize<R: std::io::BufRead>(reader: &mut R) -> std::result::Result<Self, std::io::Error> {
Ok(#return_value)
}
}
Expand Down
6 changes: 3 additions & 3 deletions borsh-rs/borsh-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "borsh-derive"
version = "0.5.0"
version = "0.6.0"
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -16,7 +16,7 @@ Binary Object Representation Serializer for Hashing
proc-macro = true

[dependencies]
borsh-derive-internal = { path = "../borsh-derive-internal" , version="0.5.0"}
borsh-schema-derive-internal = { path = "../borsh-schema-derive-internal" , version="0.5.0"}
borsh-derive-internal = { path = "../borsh-derive-internal" , version="0.6.0"}
borsh-schema-derive-internal = { path = "../borsh-schema-derive-internal" , version="0.6.0"}
syn = {version = "1", features = ["full", "fold"] }

2 changes: 1 addition & 1 deletion borsh-rs/borsh-schema-derive-internal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "borsh-schema-derive-internal"
version = "0.5.0"
version = "0.6.0"
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions borsh-rs/borsh/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "borsh"
version = "0.5.0"
version = "0.6.0"
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -21,7 +21,7 @@ name = "generate_schema_schema"
path = "src/generate_schema_schema.rs"

[dependencies]
borsh-derive = { path = "../borsh-derive", version = "0.5.0" }
borsh-derive = { path = "../borsh-derive", version = "0.6.0" }

[features]
default = ["std"]
Expand Down
10 changes: 10 additions & 0 deletions borsh-rs/borsh/src/de/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ pub fn cautious<T>(hint: u32) -> usize {
let el_size = std::mem::size_of::<T>() as u32;
std::cmp::max(std::cmp::min(hint, 4096/el_size), 1u32) as _
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
pub fn test_cautious_u8() {
assert_eq!(cautious::<u8>(10), 10);
}
}
Loading