Skip to content
This repository was archived by the owner on May 20, 2024. It is now read-only.

Commit b82617c

Browse files
committed
Add cases for simd-json-derive and update to 0.7
Signed-off-by: Heinz N. Gies <[email protected]>
1 parent de23484 commit b82617c

File tree

10 files changed

+470
-64
lines changed

10 files changed

+470
-64
lines changed

Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ edition = "2021"
66
publish = false
77

88
[dependencies]
9+
910
getopts = "0.2"
1011
jemallocator = "0.5"
1112
rustc-serialize = { version = "0.3", optional = true }
1213
serde = { version = "1.0", features = ["derive"], optional = true }
1314
serde_json = { version = "1.0", optional = true }
14-
simd-json = { version = "0.7", optional = true}
1515
time = "0.3"
16+
simd-json = { version = "0.7", optional = true }
17+
simd-json-derive = { version = "0.7", optional = true }
1618

1719
[features]
1820
default = ["performance", "all-libs", "all-files"]
1921
all-libs = ["lib-serde", "lib-rustc-serialize", "lib-simd-json"]
2022
all-files = ["file-canada", "file-citm-catalog", "file-twitter"]
2123
performance = ["parse-dom", "stringify-dom", "parse-struct", "stringify-struct"]
2224
lib-serde = ["serde", "serde_json"]
23-
lib-simd-json = ["serde", "simd-json"]
25+
lib-simd-json = ["serde", "simd-json", "simd-json-derive"]
2426
lib-rustc-serialize = ["rustc-serialize"]
2527
file-canada = []
2628
file-citm-catalog = []

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ are:
55

66
- [serde\_json] 1.0.72
77
- [rustc-serialize] 0.3.24
8-
- [simd-json] 0.4.11 (this requires a modern x86 CPU for good results)
8+
- [simd-json] 0.7.0 (this requires a modern x86 CPU for good results)
99

1010
[nativejson-benchmark]: https://github.com/miloyip/nativejson-benchmark
1111
[serde\_json]: https://github.com/serde-rs/json
1212
[rustc-serialize]: https://github.com/rust-lang-nursery/rustc-serialize
13-
[simd-json]: https://github.com/Licenser/simdjson-rs
13+
[simd-json]: https://github.com/simd-lite/simd-json
1414

1515
#### `$ cargo run --release`
1616

src/canada.rs

+36-6
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,56 @@ use std::collections::BTreeMap as Map;
66
pub type Canada = FeatureCollection;
77

88
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9-
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
9+
#[cfg_attr(
10+
any(feature = "serde", feature = "lib-simd-json"),
11+
serde(deny_unknown_fields)
12+
)]
13+
#[cfg_attr(
14+
feature = "lib-simd-json",
15+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
16+
)]
1017
pub struct FeatureCollection {
11-
#[cfg_attr(feature = "serde", serde(rename = "type"))]
18+
#[cfg_attr(
19+
any(feature = "serde", feature = "lib-simd-json"),
20+
serde(rename = "type")
21+
)]
1222
pub obj_type: ObjType,
1323
pub features: Vec<Feature>,
1424
}
1525

1626
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
17-
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
27+
#[cfg_attr(
28+
any(feature = "serde", feature = "lib-simd-json"),
29+
serde(deny_unknown_fields)
30+
)]
31+
#[cfg_attr(
32+
feature = "lib-simd-json",
33+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
34+
)]
1835
pub struct Feature {
19-
#[cfg_attr(feature = "serde", serde(rename = "type"))]
36+
#[cfg_attr(
37+
any(feature = "serde", feature = "lib-simd-json"),
38+
serde(rename = "type")
39+
)]
2040
pub obj_type: ObjType,
2141
pub properties: Map<String, String>,
2242
pub geometry: Geometry,
2343
}
2444

2545
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
26-
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
46+
#[cfg_attr(
47+
any(feature = "serde", feature = "lib-simd-json"),
48+
serde(deny_unknown_fields)
49+
)]
50+
#[cfg_attr(
51+
feature = "lib-simd-json",
52+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
53+
)]
2754
pub struct Geometry {
28-
#[cfg_attr(feature = "serde", serde(rename = "type"))]
55+
#[cfg_attr(
56+
any(feature = "serde", feature = "lib-simd-json"),
57+
serde(rename = "type")
58+
)]
2959
pub obj_type: ObjType,
3060
pub coordinates: Vec<Vec<(Latitude, Longitude)>>,
3161
}

src/color.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use serde::de::{self, Deserialize, Deserializer, Unexpected};
1212
#[cfg(feature = "serde")]
1313
use serde::ser::{Serialize, Serializer};
1414

15-
#[derive(Clone, Copy)]
15+
#[derive(Clone, Copy, Debug)]
1616
pub struct Color(u32);
1717

1818
#[cfg(any(feature = "serde", feature = "lib-rustc-serialize"))]
@@ -58,6 +58,17 @@ impl Serialize for Color {
5858
}
5959
}
6060

61+
#[cfg(feature = "lib-simd-json")]
62+
impl simd_json_derive::Serialize for Color {
63+
fn json_write<W>(&self, writer: &mut W) -> std::io::Result<()>
64+
where
65+
W: std::io::Write,
66+
{
67+
let mut buf = MaybeUninit::uninit();
68+
self.as_str(&mut buf).json_write(writer)
69+
}
70+
}
71+
6172
#[cfg(feature = "serde")]
6273
impl<'de> Deserialize<'de> for Color {
6374
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@@ -88,6 +99,29 @@ impl<'de> Deserialize<'de> for Color {
8899
}
89100
}
90101

102+
#[cfg(feature = "lib-simd-json")]
103+
impl<'input> ::simd_json_derive::Deserialize<'input> for Color {
104+
#[inline]
105+
fn from_tape(tape: &mut ::simd_json_derive::Tape<'input>) -> simd_json::Result<Self>
106+
where
107+
Self: std::marker::Sized + 'input,
108+
{
109+
if let Some(::simd_json::Node::String(s)) = tape.next() {
110+
if let Ok(hex) = u32::from_str_radix(s, 16) {
111+
Ok(Color(hex))
112+
} else {
113+
dbg!(Err(::simd_json::Error::generic(
114+
simd_json::ErrorType::ExpectedString,
115+
)))
116+
}
117+
} else {
118+
dbg!(Err(::simd_json::Error::generic(
119+
simd_json::ErrorType::ExpectedString,
120+
)))
121+
}
122+
}
123+
}
124+
91125
#[cfg(feature = "lib-rustc-serialize")]
92126
impl Encodable for Color {
93127
fn encode<S>(&self, s: &mut S) -> Result<(), S::Error>

src/copy/citm_catalog.rs

+54-12
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ use std::collections::BTreeMap as Map;
66
use crate::empty;
77
use crate::prim_str::PrimStr;
88

9-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
109
#[cfg_attr(
11-
feature = "serde",
10+
any(feature = "serde", feature = "lib-simd-json"),
11+
derive(Serialize, Deserialize)
12+
)]
13+
#[cfg_attr(
14+
any(feature = "serde", feature = "lib-simd-json"),
1215
serde(deny_unknown_fields, rename_all = "camelCase")
1316
)]
17+
#[cfg_attr(
18+
feature = "lib-simd-json",
19+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
20+
)]
1421
pub struct CitmCatalog {
1522
pub area_names: Map<IdStr, String>,
1623
pub audience_sub_category_names: Map<IdStr, String>,
@@ -28,11 +35,18 @@ pub struct CitmCatalog {
2835
pub type Id = u32;
2936
pub type IdStr = PrimStr<u32>;
3037

31-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3238
#[cfg_attr(
33-
feature = "serde",
39+
any(feature = "serde", feature = "lib-simd-json"),
40+
derive(Serialize, Deserialize)
41+
)]
42+
#[cfg_attr(
43+
any(feature = "serde", feature = "lib-simd-json"),
3444
serde(deny_unknown_fields, rename_all = "camelCase")
3545
)]
46+
#[cfg_attr(
47+
feature = "lib-simd-json",
48+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
49+
)]
3650
pub struct Event {
3751
pub description: (),
3852
pub id: Id,
@@ -44,11 +58,18 @@ pub struct Event {
4458
pub topic_ids: Vec<Id>,
4559
}
4660

47-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4861
#[cfg_attr(
49-
feature = "serde",
62+
any(feature = "serde", feature = "lib-simd-json"),
63+
derive(Serialize, Deserialize)
64+
)]
65+
#[cfg_attr(
66+
any(feature = "serde", feature = "lib-simd-json"),
5067
serde(deny_unknown_fields, rename_all = "camelCase")
5168
)]
69+
#[cfg_attr(
70+
feature = "lib-simd-json",
71+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
72+
)]
5273
pub struct Performance {
5374
pub event_id: Id,
5475
pub id: Id,
@@ -61,32 +82,53 @@ pub struct Performance {
6182
pub venue_code: String,
6283
}
6384

64-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6585
#[cfg_attr(
66-
feature = "serde",
86+
any(feature = "serde", feature = "lib-simd-json"),
87+
derive(Serialize, Deserialize)
88+
)]
89+
#[cfg_attr(
90+
any(feature = "serde", feature = "lib-simd-json"),
6791
serde(deny_unknown_fields, rename_all = "camelCase")
6892
)]
93+
#[cfg_attr(
94+
feature = "lib-simd-json",
95+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
96+
)]
6997
pub struct Price {
7098
pub amount: u32,
7199
pub audience_sub_category_id: Id,
72100
pub seat_category_id: Id,
73101
}
74102

75-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
76103
#[cfg_attr(
77-
feature = "serde",
104+
any(feature = "serde", feature = "lib-simd-json"),
105+
derive(Serialize, Deserialize)
106+
)]
107+
#[cfg_attr(
108+
any(feature = "serde", feature = "lib-simd-json"),
78109
serde(deny_unknown_fields, rename_all = "camelCase")
79110
)]
111+
#[cfg_attr(
112+
feature = "lib-simd-json",
113+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
114+
)]
80115
pub struct SeatCategory {
81116
pub areas: Vec<Area>,
82117
pub seat_category_id: Id,
83118
}
84119

85-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
86120
#[cfg_attr(
87-
feature = "serde",
121+
any(feature = "serde", feature = "lib-simd-json"),
122+
derive(Serialize, Deserialize)
123+
)]
124+
#[cfg_attr(
125+
any(feature = "serde", feature = "lib-simd-json"),
88126
serde(deny_unknown_fields, rename_all = "camelCase")
89127
)]
128+
#[cfg_attr(
129+
feature = "lib-simd-json",
130+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
131+
)]
90132
pub struct Area {
91133
pub area_id: Id,
92134
pub block_ids: empty::Array,

0 commit comments

Comments
 (0)