Skip to content

Commit

Permalink
don't leak memory in native bench
Browse files Browse the repository at this point in the history
  • Loading branch information
r58Playz committed Mar 7, 2025
1 parent da2819d commit 788ea60
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rewriter/native/flamegraph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions rewriter/native/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn dorewrite<'alloc>(alloc: &'alloc Allocator, data: &str) -> Result<RewriteResu
prefix: "/scrammedjet/",
base: "https://google.com/glorngle/si.js",
urlrewriter: Box::new(move |x: &str, alloc: &'alloc Allocator| {
String::from_str_in(encode(url.join(&x).unwrap().as_str()).as_ref(), alloc)
String::from_str_in(encode(url.join(x).unwrap().as_str()).as_ref(), alloc)
}),

sourcetag: "glongle1",
Expand Down Expand Up @@ -106,12 +106,13 @@ fn main() -> Result<()> {
let data = fs::read_to_string(file).context("failed to read file")?;
let bench = env::args().nth(2).is_some();

let alloc = Allocator::default();
let mut alloc = Allocator::default();

if bench {
let mut i = 0;
loop {
let _ = dorewrite(&alloc, &data);
alloc.reset();
i += 1;
if i % 100 == 0 {
println!("{i}...");
Expand Down

0 comments on commit 788ea60

Please sign in to comment.