Skip to content

Commit

Permalink
Add owned value
Browse files Browse the repository at this point in the history
Signed-off-by: Heinz N. Gies <[email protected]>
  • Loading branch information
Licenser committed Aug 13, 2024
1 parent 5259c2a commit c528671
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ macro_rules! json_internal_owned {
};

([]) => {
$crate::value::owned::Value::Array(json_internal_vec![])
$crate::value::owned::Value::Array(Box::new(json_internal_vec![]))
};

([ $($tt:tt)+ ]) => {
$crate::value::owned::Value::Array(json_internal_owned!(@array [] $($tt)+))
$crate::value::owned::Value::Array(Box::new(json_internal_owned!(@array [] $($tt)+)))
};

({}) => {
Expand Down
2 changes: 1 addition & 1 deletion src/serde/value/owned/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ impl<'de> Visitor<'de> for ValueVisitor {
while let Some(e) = seq.next_element()? {
v.push(e);
}
Ok(Value::Array(v))
Ok(Value::Array(Box::new(v)))
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/serde/value/owned/se.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Serialize for Value {
Value::String(s) => serializer.serialize_str(s),
Value::Array(v) => {
let mut seq = serializer.serialize_seq(Some(v.len()))?;
for e in v {
for e in v.as_ref() {
seq.serialize_element(e)?;
}
seq.end()
Expand Down Expand Up @@ -284,7 +284,7 @@ impl serde::ser::SerializeSeq for SerializeVec {
}

fn end(self) -> Result<Value> {
Ok(Value::Array(self.vec))
Ok(Value::Array(Box::new(self.vec)))
}
}

Expand Down Expand Up @@ -334,7 +334,7 @@ impl serde::ser::SerializeTupleVariant for SerializeTupleVariant {

fn end(self) -> Result<Value> {
let mut object = Object::with_capacity_and_hasher(1, ObjectHasher::default());
object.insert_nocheck(self.name, Value::Array(self.vec));
object.insert_nocheck(self.name, Value::Array(Box::new(self.vec)));
Ok(Value::from(object))
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn empty_array() {
let d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("parse_serde");
let v_simd: serde_json::Value = from_slice(d).expect("parse_simd");
assert_eq!(to_value(d1), Ok(Value::Array(vec![])));
assert_eq!(to_value(d1), Ok(Value::array()));
assert_eq!(v_simd, v_serde);
}

Expand Down Expand Up @@ -225,7 +225,7 @@ fn double_array() {
let d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("parse_serde");
let v_simd: serde_json::Value = from_slice(d).expect("parse_simd");
assert_eq!(to_value(d1), Ok(Value::Array(vec![Value::Array(vec![])])));
assert_eq!(to_value(d1), Ok(Value::from(vec![Value::array()])));
assert_eq!(v_simd, v_serde);
}

Expand All @@ -239,8 +239,8 @@ fn null_null_array() {
let v_simd: serde_json::Value = from_slice(d).expect("parse_simd");
assert_eq!(
to_value(d1),
Ok(Value::Array(vec![
Value::Array(vec![]),
Ok(Value::from(vec![
Value::array(),
Value::Static(StaticNode::Null),
Value::Static(StaticNode::Null),
]))
Expand All @@ -254,7 +254,7 @@ fn one_element_array() {
let mut d1 = d.clone();
let d1 = unsafe { d1.as_bytes_mut() };
let d = unsafe { d.as_bytes_mut() };
assert_eq!(to_value(d1), Ok(Value::Array(vec![Value::from("snot")])));
assert_eq!(to_value(d1), Ok(Value::from(vec![Value::from("snot")])));
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(d).expect("");
assert_eq!(v_simd, v_serde);
Expand All @@ -268,7 +268,7 @@ fn two_element_array() {
let d = unsafe { d.as_bytes_mut() };
assert_eq!(
to_value(d1),
Ok(Value::Array(vec![
Ok(Value::from(vec![
Value::from("snot"),
Value::from("badger")
]))
Expand All @@ -289,7 +289,7 @@ fn list() {
assert_eq!(v_simd, v_serde);
assert_eq!(
to_value(d1),
Ok(Value::Array(vec![
Ok(Value::from(vec![
Value::from(42),
Value::from(23.0),
Value::from("snot badger")
Expand All @@ -305,9 +305,9 @@ fn nested_list1() {
let d = unsafe { d.as_bytes_mut() };
assert_eq!(
to_value(d1),
Ok(Value::Array(vec![
Ok(Value::from(vec![
Value::from(42),
Value::Array(vec![Value::from(23.0), Value::from("snot")]),
Value::from(vec![Value::from(23.0), Value::from("snot")]),
Value::from("bad"),
Value::from("ger")
]))
Expand Down Expand Up @@ -366,7 +366,7 @@ fn odd_array() {
assert_eq!(v_simd, v_serde);
assert_eq!(
to_value(d1),
Ok(Value::Array(vec![
Ok(Value::from(vec![
Value::from(Object::default()),
Value::Static(StaticNode::Null)
]))
Expand Down Expand Up @@ -420,7 +420,7 @@ fn null_null() {
let d = unsafe { d.as_bytes_mut() };
assert_eq!(
to_value(d1),
Ok(Value::Array(vec![
Ok(Value::from(vec![
Value::Static(StaticNode::Null),
Value::Static(StaticNode::Null),
]))
Expand All @@ -438,7 +438,7 @@ fn nested_null() {
let d = unsafe { d.as_bytes_mut() };
assert_eq!(
to_value(d1),
Ok(Value::Array(vec![Value::Array(vec![
Ok(Value::from(vec![Value::from(vec![
Value::Static(StaticNode::Null),
Value::Static(StaticNode::Null),
])]))
Expand All @@ -460,7 +460,7 @@ fn nestednested_null() {
assert_eq!(v_simd, v_serde);
assert_eq!(
to_value(d1),
Ok(Value::Array(vec![Value::Array(vec![Value::Array(vec![
Ok(Value::from(vec![Value::from(vec![Value::from(vec![
Value::Static(StaticNode::Null),
Value::Static(StaticNode::Null),
])])]))
Expand Down
10 changes: 5 additions & 5 deletions src/value/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub enum Value {
/// string type
String(String),
/// array type
Array(Vec<Value>),
Array(Box<Vec<Value>>),
/// object type
Object(Box<Object>),
}
Expand All @@ -101,7 +101,7 @@ impl<'input> ValueBuilder<'input> for Value {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn array_with_capacity(capacity: usize) -> Self {
Self::Array(Vec::with_capacity(capacity))
Self::Array(Box::new(Vec::with_capacity(capacity)))
}
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
Expand Down Expand Up @@ -244,7 +244,7 @@ impl ValueIntoArray for Value {

fn into_array(self) -> Option<<Value as ValueIntoArray>::Array> {
match self {
Self::Array(a) => Some(a),
Self::Array(a) => Some(*a),
_ => None,
}
}
Expand Down Expand Up @@ -345,7 +345,7 @@ impl<'de> OwnedDeserializer<'de> {
}
res.set_len(len);
}
Value::Array(res)
Value::Array(Box::new(res))
}

#[cfg_attr(not(feature = "no-inline"), inline)]
Expand Down Expand Up @@ -825,7 +825,7 @@ mod test {
|inner| {
prop_oneof![
// Take the inner strategy and make the two recursive cases.
prop::collection::vec(inner.clone(), 0..10).prop_map(Value::Array),
prop::collection::vec(inner.clone(), 0..10).prop_map(Value::from),
prop::collection::hash_map(".*", inner, 0..10)
.prop_map(|m| m.into_iter().collect()),
]
Expand Down
2 changes: 1 addition & 1 deletion src/value/owned/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl PartialEq<BorrowedValue<'_>> for Value {
match (self, other) {
(Self::Static(s1), BorrowedValue::Static(s2)) => s1 == s2,
(Self::String(v1), BorrowedValue::String(v2)) => v1.eq(v2),
(Self::Array(v1), BorrowedValue::Array(v2)) => v1.eq(v2.as_ref()),
(Self::Array(v1), BorrowedValue::Array(v2)) => v1.as_ref().eq(v2.as_ref()),
(Self::Object(v1), BorrowedValue::Object(v2)) => {
if v1.len() != v2.len() {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/value/owned/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<V: Into<Value>> FromIterator<V> for Value {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn from_iter<I: IntoIterator<Item = V>>(iter: I) -> Self {
Self::Array(iter.into_iter().map(Into::into).collect())
Self::Array(Box::new(iter.into_iter().map(Into::into).collect()))
}
}

Expand Down

0 comments on commit c528671

Please sign in to comment.