-
Notifications
You must be signed in to change notification settings - Fork 827
Avoid heap usage when encoding to base58 #191
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
Conversation
src/util/base58.rs
Outdated
@@ -134,14 +177,12 @@ pub fn from_check(data: &str) -> Result<Vec<u8>, Error> { | |||
Ok(ret) | |||
} | |||
|
|||
fn encode_iter_utf8<I>(data: I) -> Vec<u8> | |||
fn encode_iter_utf8<I, W>(data: I, writer: &mut W) -> Result<(), fmt::Error> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is obvious to me that the function should be renamed since it'f no longer returning UTF-8 bytes but rather writing unicode char
s to a writer. What would you think is a good name instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format_iter
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
src/util/base58.rs
Outdated
String::from_utf8(ret).unwrap() | ||
let mut ret = String::new(); | ||
encode_iter_utf8(data, &mut ret).expect("writing into string shouldn't fail"); | ||
ret | ||
} | ||
|
||
/// Directly encode a slice as base58 into a `Formatter`. | ||
fn encode_iter_to_fmt<I>(fmt: &mut fmt::Formatter, data: I) -> fmt::Result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that this function becomes redundant.
Looks great, thanks! |
…straints overhaul interpreter ("satisfied constraints") API
Instead of always allocating a
Vec
this implementation will work on the stack only as long as the output stays below 100 characters.Closes #145