summaryrefslogtreecommitdiff
path: root/serde_v8/src/serializable.rs
diff options
context:
space:
mode:
authorAndreu Botella <andreu@andreubotella.com>2022-03-16 00:22:00 +0100
committerGitHub <noreply@github.com>2022-03-16 00:22:00 +0100
commit672f66dde1f7ec87282d37e10cac2cdd36e5f181 (patch)
treeaa662ed245efe575841d0a951d8ce36f53b48ed4 /serde_v8/src/serializable.rs
parentbb53135ed87ec063c9238e1b7de8cf3b44535685 (diff)
perf(web): Optimize `TextDecoder` by adding a new `U16String` type (#13923)
Diffstat (limited to 'serde_v8/src/serializable.rs')
-rw-r--r--serde_v8/src/serializable.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/serde_v8/src/serializable.rs b/serde_v8/src/serializable.rs
index df6912db0..533b3f83f 100644
--- a/serde_v8/src/serializable.rs
+++ b/serde_v8/src/serializable.rs
@@ -4,6 +4,7 @@ use std::mem::transmute_copy;
use crate::Buffer;
use crate::ByteString;
+use crate::U16String;
/// Serializable exists to allow boxing values as "objects" to be serialized later,
/// this is particularly useful for async op-responses. This trait is a more efficient
@@ -63,6 +64,7 @@ pub enum Primitive {
String(String),
Buffer(Buffer),
ByteString(ByteString),
+ U16String(U16String),
}
impl serde::Serialize for Primitive {
@@ -86,6 +88,7 @@ impl serde::Serialize for Primitive {
Self::String(x) => x.serialize(s),
Self::Buffer(x) => x.serialize(s),
Self::ByteString(x) => x.serialize(s),
+ Self::U16String(x) => x.serialize(s),
}
}
}
@@ -130,6 +133,8 @@ impl<T: serde::Serialize + 'static> From<T> for SerializablePkg {
Self::Primitive(Primitive::Buffer(tc(x)))
} else if tid == TypeId::of::<ByteString>() {
Self::Primitive(Primitive::ByteString(tc(x)))
+ } else if tid == TypeId::of::<U16String>() {
+ Self::Primitive(Primitive::U16String(tc(x)))
} else {
Self::Serializable(Box::new(x))
}