squeeze the last ms of performance out of the rewriter

This commit is contained in:
velzie 2024-07-17 18:42:20 -04:00
parent 213f7bfa2b
commit 41acba634d
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
5 changed files with 31 additions and 152 deletions

View file

@ -1,7 +1,8 @@
pub mod rewrite;
use std::str::FromStr;
use std::str::{from_utf8, FromStr};
use js_sys::Uint8Array;
use rewrite::rewrite;
use url::Url;
use wasm_bindgen::prelude::*;
@ -13,12 +14,12 @@ extern "C" {
}
#[wasm_bindgen]
pub fn rewrite_js(js: &str, url: &str) -> String {
pub fn rewrite_js(js: &str, url: &str) -> Vec<u8> {
rewrite(js, Url::from_str(url).unwrap())
}
#[wasm_bindgen]
pub fn rewrite_js_from_arraybuffer(js: &[u8], url: &str) -> String {
pub fn rewrite_js_from_arraybuffer(js: &[u8], url: &str) -> Vec<u8> {
// technically slower than the c++ string conversion but it will create *less copies*
let js = unsafe { std::str::from_utf8_unchecked(js) };