Skip to content

Commit

Permalink
Fix known key implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Heinz N. Gies <[email protected]>
  • Loading branch information
Licenser committed Sep 26, 2023
1 parent 94ac2e9 commit 9d0ea0e
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/impls/simdjson.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Deserialize, Serialize};
use simd_json::{BorrowedValue, Node, OwnedValue};
use value_trait::Writable;
use value_trait::{Builder, Writable};

impl Serialize for OwnedValue {
fn json_write<W>(&self, writer: &mut W) -> crate::Result
Expand Down Expand Up @@ -50,18 +50,20 @@ impl<'input, 'tape> OwnedDeser<'input, 'tape> {

#[inline(always)]
fn parse_map(&mut self, len: usize) -> OwnedValue {
let mut res = simd_json::value::owned::Object::with_capacity(len);
let mut res = OwnedValue::object_with_capacity(len);

// Since we checked if it's empty we know that we at least have one
// element so we eat this
for _ in 0..len {
if let Node::String(key) = self.0.next().unwrap() {
res.insert_nocheck(key.into(), self.parse().unwrap());
} else {
unreachable!()
if let OwnedValue::Object(ref mut res) = res {
for _ in 0..len {
if let Node::String(key) = self.0.next().unwrap() {
res.insert_nocheck(key.into(), self.parse().unwrap());
} else {
unreachable!()
}
}
}
OwnedValue::from(res)
res
}
}
impl<'input> Deserialize<'input> for OwnedValue {
Expand Down Expand Up @@ -104,18 +106,23 @@ impl<'input, 'tape> BorrowedDeser<'input, 'tape> {

#[inline(always)]
fn parse_map(&mut self, len: usize) -> BorrowedValue<'input> {
let mut res = simd_json::value::borrowed::Object::with_capacity(len);
let mut res = BorrowedValue::object_with_capacity(len);

// Since we checked if it's empty we know that we at least have one
// element so we eat this
for _ in 0..len {
if let Node::String(key) = self.0.next().unwrap() {
res.insert_nocheck(key.into(), self.parse().unwrap());
} else {
unreachable!()
if let BorrowedValue::Object(ref mut res) = res {
for _ in 0..len {
if let Node::String(key) = self.0.next().unwrap() {
res.insert_nocheck(key.into(), self.parse().unwrap());
} else {
unreachable!()
}
}
} else {
unreachable!()
}
BorrowedValue::from(res)

res
}
}
impl<'input> Deserialize<'input> for BorrowedValue<'input> {
Expand Down

0 comments on commit 9d0ea0e

Please sign in to comment.