summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2022-05-15 17:52:32 +0200
committerGitHub <noreply@github.com>2022-05-15 17:52:32 +0200
commit8744ee883e093ecc09add4054177f8afa793ec77 (patch)
treea848cb5db1b81097bc5f8421a06a8ee5b89c9d3e
parentc9e9265c3eea93cd6006546a70f3552a41718944 (diff)
perf(core): optimize encode on large strings (#14619)
Follow up to serde_v8's #14450
-rw-r--r--core/bindings.rs6
-rw-r--r--serde_v8/lib.rs2
2 files changed, 4 insertions, 4 deletions
diff --git a/core/bindings.rs b/core/bindings.rs
index 9d376fc0e..d2335d49c 100644
--- a/core/bindings.rs
+++ b/core/bindings.rs
@@ -896,11 +896,11 @@ fn encode(
return;
}
};
- let text_str = text.to_rust_string_lossy(scope);
- let bytes: Box<[u8]> = text_str.into_bytes().into_boxed_slice();
+ let text_str = serde_v8::to_utf8(text, scope);
+ let bytes = text_str.into_bytes();
let len = bytes.len();
let backing_store =
- v8::ArrayBuffer::new_backing_store_from_boxed_slice(bytes).make_shared();
+ v8::ArrayBuffer::new_backing_store_from_vec(bytes).make_shared();
let buffer = v8::ArrayBuffer::with_backing_store(scope, &backing_store);
let u8array = v8::Uint8Array::new(scope, buffer, 0, len).unwrap();
rv.set(u8array.into())
diff --git a/serde_v8/lib.rs b/serde_v8/lib.rs
index 2709f0cb5..49f669151 100644
--- a/serde_v8/lib.rs
+++ b/serde_v8/lib.rs
@@ -8,7 +8,7 @@ mod ser;
mod serializable;
pub mod utils;
-pub use de::{from_v8, from_v8_cached, Deserializer};
+pub use de::{from_v8, from_v8_cached, to_utf8, Deserializer};
pub use error::{Error, Result};
pub use keys::KeyCache;
pub use magic::buffer::ZeroCopyBuf;