Skip to content

Commit

Permalink
Optimize string decoding, simplify function
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed May 8, 2024
1 parent 383092d commit 98861f1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
4 changes: 1 addition & 3 deletions packages/std/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,7 @@ impl Api for ExternalApi {
)));
}

// TODO: Optimize this heap allocation away?
// I mean technically we save a bunch of heap allocation now anyway, but we can optimize this, too!
let address = unsafe { consume_string_region_written_by_vm(human.to_heap_ptr()) };
let address = unsafe { String::from_utf8_unchecked(human.into_vec()) };
Ok(Addr::unchecked(address))
}

Expand Down
7 changes: 1 addition & 6 deletions packages/std/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,5 @@ where
/// or zero if not present
#[cfg(feature = "iterator")]
pub fn get_optional_region_address<O: Ownership>(region: &Option<&Region<O>>) -> u32 {
/// Returns the address of the Region as an offset in linear memory
fn get_region_address<O: Ownership>(region: &Region<O>) -> u32 {
region.as_ptr() as u32
}

region.map(get_region_address).unwrap_or(0)
region.map(|r| r.as_ptr() as u32).unwrap_or(0)
}

0 comments on commit 98861f1

Please sign in to comment.