Skip to content

Commit 0a38780

Browse files
committed
refactor: reduce smallvec dep from git-date
Signed-off-by: tison <wander4096@gmail.com>
1 parent 575113d commit 0a38780

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-date/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ bstr = { version = "1.12.0", default-features = false, features = ["std"] }
2424
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
2525
itoa = "1.0.17"
2626
jiff = "0.2.24"
27-
# TODO: used for quick and easy `TimeBacking: std::io::Write` implementation, but could make that `Copy`
28-
# and remove this dep with custom impl
29-
smallvec = { version = "1.15.1", features = ["write"] }
3027

3128
document-features = { version = "0.2.0", optional = true }
3229

gix-date/src/parse/mod.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1+
use std::io;
12
use std::str::FromStr;
23

34
use crate::{Error, Time};
4-
use smallvec::SmallVec;
55

66
/// A container for just enough bytes to hold the largest-possible [`time`](Time) instance.
7-
/// It's used in conjunction with
87
#[derive(Default, Clone)]
98
pub struct TimeBuf {
10-
buf: SmallVec<[u8; Time::MAX.size()]>,
9+
idx: usize,
10+
buf: [u8; Time::MAX.size()],
11+
}
12+
13+
impl io::Write for TimeBuf {
14+
fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {
15+
let end_idx = self.idx + buf.len();
16+
if end_idx > Time::MAX.size() {
17+
return Err(io::Error::from(io::ErrorKind::StorageFull));
18+
}
19+
self.buf[self.idx..end_idx].copy_from_slice(buf);
20+
self.idx = end_idx;
21+
Ok(buf.len())
22+
}
23+
24+
fn flush(&mut self) -> io::Result<()> {
25+
Ok(())
26+
}
1127
}
1228

1329
impl TimeBuf {
@@ -21,7 +37,7 @@ impl TimeBuf {
2137

2238
/// Clear the previous content.
2339
fn clear(&mut self) {
24-
self.buf.clear();
40+
self.idx = 0;
2541
}
2642
}
2743

@@ -30,7 +46,7 @@ impl Time {
3046
/// and return `buf` as `&str` for easy consumption.
3147
pub fn to_str<'a>(&self, buf: &'a mut TimeBuf) -> &'a str {
3248
buf.clear();
33-
self.write_to(&mut buf.buf)
49+
self.write_to(buf)
3450
.expect("write to memory of just the right size cannot fail");
3551
buf.as_str()
3652
}

0 commit comments

Comments
 (0)