Skip to content

Commit

Permalink
fix: remove unused codes
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 committed Nov 2, 2024
1 parent e257fb9 commit a06c67b
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 137 deletions.
51 changes: 0 additions & 51 deletions benchmarks/benches/deserialize_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,6 @@ fn sonic_rs_to_simdjson_value(data: &[u8]) {
let _: simd_json::OwnedValue = sonic_rs::from_slice(data).unwrap();
}

fn sonic_rs_to_newvalue(data: &[u8]) {
let mut value = sonic_rs::NewValue::Null;
value.parse_with_padding(data).unwrap();
}

fn sonic_rs_to_newvalue2(data: &[u8]) {
let mut value = sonic_rs::NewValue2::Null;
value.parse_with_padding(data).unwrap();
}

fn sonic_rs_to_newvalue2_without(data: &[u8]) {
let mut value = sonic_rs::NewValue2::Null;
value.parse_without_padding(data).unwrap();
}

macro_rules! bench_file {
($name:ident) => {
#[allow(unused)]
Expand Down Expand Up @@ -130,42 +115,6 @@ macro_rules! bench_file {
},
);

group.bench_with_input(
"sonic_rs_to_newvalue::from_slice_unchecked",
&vec,
|b, data| {
b.iter_batched(
|| data,
|bytes| sonic_rs_to_newvalue(&bytes),
BatchSize::SmallInput,
)
},
);

group.bench_with_input(
"sonic_rs_to_newvalue2::from_slice_unchecked",
&vec,
|b, data| {
b.iter_batched(
|| data,
|bytes| sonic_rs_to_newvalue2(&bytes),
BatchSize::SmallInput,
)
},
);

group.bench_with_input(
"sonic_rs_to_newvalue2_without::from_slice_unchecked",
&vec,
|b, data| {
b.iter_batched(
|| data,
|bytes| sonic_rs_to_newvalue2_without(&bytes),
BatchSize::SmallInput,
)
},
);

// group.bench_with_input("sonic_rs::skip_one", &vec, |b, data| {
// b.iter_batched(
// || data,
Expand Down
1 change: 0 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ where
/// // use pointer for retrieving nested values
/// assert_eq!(data.pointer(&pointer!["x", "y", 0]).unwrap(), &json!("z"));
/// ```

#[inline]
fn index(&self, index: I) -> &Value {
static NULL: Value = Value::new();
Expand Down
2 changes: 1 addition & 1 deletion src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'de> From<&'de String> for JsonSlice<'de> {
}
}

impl<'de> From<String> for JsonSlice<'de> {
impl From<String> for JsonSlice<'_> {
fn from(value: String) -> Self {
JsonSlice::FastStr(FastStr::new(value))
}
Expand Down
5 changes: 4 additions & 1 deletion src/lazyvalue/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ impl<'a> Hash for LazyValue<'a> {
}

impl<'a> JsonValueTrait for LazyValue<'a> {
type ValueType<'v> = LazyValue<'v> where Self: 'v;
type ValueType<'v>
= LazyValue<'v>
where
Self: 'v;

fn as_bool(&self) -> Option<bool> {
match self.raw.as_ref() {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg_attr(not(doctest), doc = include_str!("../README.md"))]
#![allow(dead_code)]
#![allow(clippy::needless_lifetimes)]
#![doc(test(attr(warn(unused))))]

mod error;
Expand Down
50 changes: 3 additions & 47 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::{
unicode::{codepoint_to_utf8, hex_to_u32_nocheck},
},
value::{shared::Shared, visitor::JsonVisitor},
JsonType, LazyValue,
LazyValue,
};

pub(crate) const DEFAULT_KEY_BUF_CAPACITY: usize = 128;
Expand Down Expand Up @@ -220,22 +220,6 @@ where
}
}

#[inline(always)]
fn parse_string<V>(&mut self, visitor: &mut V, strbuf: &mut Vec<u8>) -> Result<()>
where
V: JsonVisitor<'de>,
{
let ok = match self.parse_str_impl(strbuf)? {
Reference::Borrowed(s) => visitor.visit_borrowed_str(s),
Reference::Copied(s) => visitor.visit_str(s),
};
if !ok {
perr!(self, UnexpectedVisitType)
} else {
Ok(())
}
}

// TODO: optimize me, avoid clone twice.
#[inline(always)]
fn parse_string_owned<V>(&mut self, visitor: &mut V, strbuf: &mut Vec<u8>) -> Result<()>
Expand Down Expand Up @@ -357,19 +341,6 @@ where
}
}

#[inline(always)]
fn parse_key<V>(&mut self, visitor: &mut V, strbuf: &mut Vec<u8>) -> Result<()>
where
V: JsonVisitor<'de>,
{
let ok = match self.parse_str_impl(strbuf)? {
Reference::Borrowed(s) => visitor.visit_borrowed_key(s),
Reference::Copied(s) => visitor.visit_key(s),
};
check_visit!(self, ok);
Ok(())
}

#[inline(always)]
fn parse_object<V>(&mut self, visitor: &mut V) -> Result<()>
where
Expand Down Expand Up @@ -442,19 +413,6 @@ where
}
}

#[inline]
pub(crate) fn get_json_type(&mut self) -> Result<JsonType> {
match self.skip_space_peek() {
Some(b'-') | Some(b'0'..=b'9') => Ok(JsonType::Number),
Some(b'"') => Ok(JsonType::String),
Some(b'{') => Ok(JsonType::Object),
Some(b'[') => Ok(JsonType::Array),
Some(b't') | Some(b'f') => Ok(JsonType::Boolean),
Some(b'n') => Ok(JsonType::Null),
_ => perr!(self, EofWhileParsing),
}
}

#[inline]
pub(crate) fn parse_array_elem_lazy(
&mut self,
Expand Down Expand Up @@ -1762,10 +1720,6 @@ where
Ok(())
}

pub(crate) fn get_from(&mut self, path: &JsonPointer) -> Result<(&'de [u8], ParseStatus)> {
self.get_from_with_iter(path.iter())
}

pub(crate) fn get_from_with_iter<P: IntoIterator>(
&mut self,
path: P,
Expand Down Expand Up @@ -1983,10 +1937,12 @@ where
}
}

#[cfg(test)]
pub(crate) fn remain_str(&self) -> &'de str {
as_str(self.remain_u8_slice())
}

#[cfg(test)]
pub(crate) fn remain_u8_slice(&self) -> &'de [u8] {
let reader = &self.read;
let start = reader.index();
Expand Down
15 changes: 0 additions & 15 deletions src/util/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,6 @@ pub(crate) struct ArcInner<T> {
refcnt: atomic::AtomicUsize,
}

impl<T> ArcInner<T> {
#[inline]
pub(crate) fn new(data: T) -> Self {
Self {
refcnt: atomic::AtomicUsize::new(1),
data,
}
}

#[inline]
pub(crate) fn data(&self) -> &T {
&self.data
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
2 changes: 0 additions & 2 deletions src/util/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ macro_rules! check_digit {
};
}

const DEFAULT_U8: u8 = 0_u8;

#[inline(always)]
fn parse_exponent(data: &[u8], index: &mut usize) -> Result<i32, ErrorCode> {
let mut exponent: i32 = 0;
Expand Down
5 changes: 0 additions & 5 deletions src/value/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,11 +1612,6 @@ impl<'a> DocumentVisitor<'a> {
}
}

#[inline(always)]
fn shared(&self) -> *const Shared {
self.shared
}

#[inline(always)]
fn nodes(&mut self) -> &mut Vec<ManuallyDrop<Value>> {
unsafe { self.nodes.as_mut() }
Expand Down
14 changes: 1 addition & 13 deletions src/value/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ pub(crate) struct SerializeTupleVariant {
vec: Value,
}

/// Serializing Rust into `Value`. We has special handling for `Number`, `RawNumber` and `RawValue`.
/// Serializing Rust into `Value`. We has special handling for `Number`, `RawNumber`.
pub(crate) struct SerializeMap {
map: MapInner,
shared: NonNull<Shared>,
Expand All @@ -387,9 +387,6 @@ enum MapInner {
RawNumber {
out_value: Option<Value>,
},
RawValue {
out_value: Option<Value>,
},
}

/// Serializing Rust struct variant into `Value`.
Expand Down Expand Up @@ -481,7 +478,6 @@ impl serde::ser::SerializeMap for SerializeMap {
Ok(())
}
MapInner::RawNumber { .. } => unreachable!(),
MapInner::RawValue { .. } => unreachable!(),
}
}

Expand All @@ -499,15 +495,13 @@ impl serde::ser::SerializeMap for SerializeMap {
Ok(())
}
MapInner::RawNumber { .. } => unreachable!(),
MapInner::RawValue { .. } => unreachable!(),
}
}

fn end(self) -> Result<Value> {
match self.map {
MapInner::Object { object, .. } => Ok(object),
MapInner::RawNumber { .. } => unreachable!(),
MapInner::RawValue { .. } => unreachable!(),
}
}
}
Expand Down Expand Up @@ -724,9 +718,6 @@ impl serde::ser::SerializeStruct for SerializeMap {
MapInner::RawNumber { out_value: _ } => {
todo!()
}
MapInner::RawValue { out_value: _ } => {
todo!()
}
}
}

Expand All @@ -736,9 +727,6 @@ impl serde::ser::SerializeStruct for SerializeMap {
MapInner::RawNumber { out_value, .. } => {
Ok(out_value.expect("number value was not emitted"))
}
MapInner::RawValue { out_value, .. } => {
Ok(out_value.expect("raw value was not emitted"))
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/value/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@ pub(crate) trait JsonVisitor<'de> {
false
}

#[allow(dead_code)]
fn visit_u64(&mut self, _val: u64) -> bool {
false
}

#[allow(dead_code)]
fn visit_i64(&mut self, _val: i64) -> bool {
false
}

#[allow(dead_code)]
fn visit_f64(&mut self, _val: f64) -> bool {
false
}

#[allow(dead_code)]
fn visit_raw_number(&mut self, _val: &str) -> bool {
false
}

#[allow(dead_code)]
fn visit_borrowed_raw_number(&mut self, _val: &str) -> bool {
false
}
Expand Down Expand Up @@ -51,10 +56,12 @@ pub(crate) trait JsonVisitor<'de> {
false
}

#[allow(dead_code)]
fn visit_key(&mut self, _key: &str) -> bool {
false
}

#[allow(dead_code)]
fn visit_borrowed_key(&mut self, _key: &'de str) -> bool {
false
}
Expand Down

0 comments on commit a06c67b

Please sign in to comment.