Skip to content

Commit 77e2d4a

Browse files
committed
Switch from cbor to bincode
1 parent 8d42961 commit 77e2d4a

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

Cargo.lock

+10-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ lazy_static = "1.4.0"
1717
version = "1.0"
1818
features = ["std", "derive"]
1919

20-
[dependencies.serde_cbor]
21-
version = "0.11"
20+
[dependencies.bincode]
21+
version = "1.3"
2222

2323
[target.'cfg(windows)'.dependencies]
2424
kernel32-sys = "0.2.2"

src/db.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::io::BufWriter;
1818
use std::io::Read;
1919
use std::io::Write;
2020

21-
const VERSION: u32 = 2;
21+
const VERSION: u32 = 3;
2222

2323
/// Files are identified by integers that are stable across n2 executions.
2424
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
@@ -80,13 +80,25 @@ impl Writer {
8080
})
8181
}
8282

83+
fn read_entry(reader: &mut BufReader<&mut File>) -> bincode::Result<Option<DbEntry>> {
84+
let result = bincode::deserialize_from(reader);
85+
if let Err(boxed) = &result {
86+
if let bincode::ErrorKind::Io(err) = boxed.as_ref() {
87+
if err.kind() == std::io::ErrorKind::UnexpectedEof {
88+
return Ok(None);
89+
}
90+
}
91+
}
92+
result.map(Some)
93+
}
94+
8395
fn open(mut f: File, graph: &mut Graph, hashes: &mut Hashes) -> anyhow::Result<Self> {
8496
let mut reader = BufReader::with_capacity(1usize << 16, &mut f);
8597
read_signature(&mut reader)?;
8698
let mut ids = IdMap::default();
8799

88-
for entry in serde_cbor::Deserializer::from_reader(&mut reader).into_iter() {
89-
match entry? {
100+
while let Some(entry) = Self::read_entry(&mut reader)? {
101+
match entry {
90102
DbEntry::File(mut name) => {
91103
let file_id = graph.file_id(&mut name);
92104
let db_id = ids.fileids.push(file_id);
@@ -128,7 +140,7 @@ impl Writer {
128140
let id = self.ids.fileids.push(fileid);
129141
self.ids.db_ids.insert(fileid, id);
130142
let entry = DbEntry::File(graph.file(fileid).name.to_owned());
131-
serde_cbor::ser::to_writer(&mut self.w, &entry)?;
143+
bincode::serialize_into(&mut self.w, &entry)?;
132144
id
133145
}
134146
};
@@ -148,7 +160,7 @@ impl Writer {
148160
.map(|&file_id| self.ensure_id(graph, file_id))
149161
.collect::<anyhow::Result<Vec<_>>>()?;
150162
let entry = DbEntry::Build { outs, deps, hash };
151-
serde_cbor::ser::to_writer(&mut self.w, &entry)?;
163+
bincode::serialize_into(&mut self.w, &entry)?;
152164
self.w.flush()?;
153165
Ok(())
154166
}

0 commit comments

Comments
 (0)