Remove need to use null when passing Rust strings (#4756)

This commit is contained in:
Jack May
2019-06-20 19:09:50 -07:00
committed by GitHub
parent ada4d16c4c
commit 425ac8d520
2 changed files with 40 additions and 15 deletions

View File

@ -27,22 +27,13 @@ macro_rules! info {
/// Prints a string to stdout
///
/// @param message - Message to print
#[inline(never)] // prevent inline so everyone does not incur stack cost
pub fn sol_log(message: &str) {
// Not pretty but 1/3 faster then using `clone_from_slice()`
let mut buf: [u8; 128] = [0; 128];
for (i, b) in message.as_bytes().iter().enumerate() {
if i > 127 {
break;
}
buf[i] = *b;
}
unsafe {
sol_log_(buf.as_ptr());
sol_log_(message.as_ptr(), message.len() as u64);
}
}
extern "C" {
fn sol_log_(message: *const u8);
fn sol_log_(message: *const u8, length: u64);
}
/// Prints 64 bit values represented as hexadecimal to stdout