Commit 6df1d205 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by Jiachi Liu

chore: Update patricia_tree dependency, remove manual serde impls (#85785)

Recent versions of `patricia_tree` have their own serde implementation which is more efficient than what we can do because it serializes the internal nodes in the tree, rather than the public observable key/value entry API.
parent 88581b91
...@@ -4944,11 +4944,11 @@ checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" ...@@ -4944,11 +4944,11 @@ checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]] [[package]]
name = "patricia_tree" name = "patricia_tree"
version = "0.5.5" version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "062a6297f2cd3969a780156ccb288eafb34bb5ed0f3c9a2b4500dbde869d4b86" checksum = "4df0e43512f12f23a6b08c7b893192b7d6ec937b95ee03af040847907fe5cef7"
dependencies = [ dependencies = [
"bitflags 1.3.2", "serde",
] ]
[[package]] [[package]]
......
...@@ -23,7 +23,7 @@ data-encoding = { workspace = true } ...@@ -23,7 +23,7 @@ data-encoding = { workspace = true }
either = { workspace = true } either = { workspace = true }
indexmap = { workspace = true } indexmap = { workspace = true }
once_cell = { workspace = true } once_cell = { workspace = true }
patricia_tree = "0.5.5" patricia_tree = { version = "0.10.1", features = ["serde"] }
petgraph = { workspace = true, features = ["serde-1"] } petgraph = { workspace = true, features = ["serde-1"] }
roaring = { workspace = true, features = ["serde"] } roaring = { workspace = true, features = ["serde"] }
ref-cast = "1.0.20" ref-cast = "1.0.20"
......
...@@ -6,12 +6,7 @@ use std::{ ...@@ -6,12 +6,7 @@ use std::{
use anyhow::Result; use anyhow::Result;
use patricia_tree::PatriciaMap; use patricia_tree::PatriciaMap;
use serde::{ use serde::{Deserialize, Serialize};
Deserialize, Deserializer, Serialize, Serializer,
de::{MapAccess, Visitor},
ser::SerializeMap,
};
use serde_bytes::{ByteBuf, Bytes};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
NonLocalValue, NonLocalValue,
...@@ -29,7 +24,8 @@ use super::pattern::Pattern; ...@@ -29,7 +24,8 @@ use super::pattern::Pattern;
/// ///
/// If the pattern does not have a wildcard character, it will only match the /// If the pattern does not have a wildcard character, it will only match the
/// exact string, and return the template as-is. /// exact string, and return the template as-is.
#[derive(Clone)] #[derive(Clone, Serialize, Deserialize)]
#[serde(transparent)]
pub struct AliasMap<T> { pub struct AliasMap<T> {
map: PatriciaMap<BTreeMap<AliasKey, T>>, map: PatriciaMap<BTreeMap<AliasKey, T>>,
} }
...@@ -55,63 +51,6 @@ where ...@@ -55,63 +51,6 @@ where
impl<T> Eq for AliasMap<T> where T: Eq {} impl<T> Eq for AliasMap<T> where T: Eq {}
impl<T> Serialize for AliasMap<T>
where
T: Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut map = serializer.serialize_map(Some(self.map.len()))?;
for (prefix, value) in self.map.iter() {
let key = ByteBuf::from(prefix);
map.serialize_entry(&key, value)?;
}
map.end()
}
}
struct AliasMapVisitor<T> {
marker: std::marker::PhantomData<T>,
}
impl<'de, T> Visitor<'de> for AliasMapVisitor<T>
where
T: Deserialize<'de>,
{
type Value = AliasMap<T>;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("a map of alias patterns to templates")
}
fn visit_map<M>(self, mut access: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'de>,
{
let mut map = AliasMap::new();
while let Some((key, value)) = access.next_entry::<&Bytes, _>()? {
map.map.insert(key, value);
}
Ok(map)
}
}
impl<'a, T> Deserialize<'a> for AliasMap<T>
where
T: Deserialize<'a>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'a>,
{
deserializer.deserialize_map(AliasMapVisitor {
marker: std::marker::PhantomData,
})
}
}
impl<T> TraceRawVcs for AliasMap<T> impl<T> TraceRawVcs for AliasMap<T>
where where
T: TraceRawVcs, T: TraceRawVcs,
...@@ -392,7 +331,7 @@ impl<'a, T> IntoIterator for &'a AliasMap<T> { ...@@ -392,7 +331,7 @@ impl<'a, T> IntoIterator for &'a AliasMap<T> {
/// ///
/// [PATTERN_KEY_COMPARE]: https://nodejs.org/api/esm.html#resolver-algorithm-specification /// [PATTERN_KEY_COMPARE]: https://nodejs.org/api/esm.html#resolver-algorithm-specification
pub struct AliasMapIntoIter<T> { pub struct AliasMapIntoIter<T> {
iter: patricia_tree::map::IntoIter<BTreeMap<AliasKey, T>>, iter: patricia_tree::map::IntoIter<Vec<u8>, BTreeMap<AliasKey, T>>,
current_prefix_iterator: Option<AliasMapIntoIterItem<T>>, current_prefix_iterator: Option<AliasMapIntoIterItem<T>>,
} }
...@@ -457,7 +396,7 @@ impl<T> Iterator for AliasMapIntoIter<T> { ...@@ -457,7 +396,7 @@ impl<T> Iterator for AliasMapIntoIter<T> {
/// ///
/// [PATTERN_KEY_COMPARE]: https://nodejs.org/api/esm.html#resolver-algorithm-specification /// [PATTERN_KEY_COMPARE]: https://nodejs.org/api/esm.html#resolver-algorithm-specification
pub struct AliasMapIter<'a, T> { pub struct AliasMapIter<'a, T> {
iter: patricia_tree::map::Iter<'a, BTreeMap<AliasKey, T>>, iter: patricia_tree::map::Iter<'a, Vec<u8>, BTreeMap<AliasKey, T>>,
current_prefix_iterator: Option<AliasMapIterItem<'a, T>>, current_prefix_iterator: Option<AliasMapIterItem<'a, T>>,
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment