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

Commit

Permalink
Merge pull request #4 from jwodder/smartstring
Browse files Browse the repository at this point in the history
Use `smartstring` for `Component`
  • Loading branch information
jwodder authored Jul 22, 2024
2 parents fc48494 + e6d1f9c commit e7ac652
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ clap = { version = "4.3.24", default-features = false, features = ["derive", "er
get-size = { version = "0.1.4", features = ["derive"] }
serde = { version = "1.0.204", features = ["derive"] }
serde_json = { version = "1.0.120", features = ["preserve_order"] }
smartstring = "1.0.1"
thiserror = "1.0.62"
thousands = "0.2.0"
time = { version = "0.3.36", features = ["parsing", "serde"] }
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ Examples
```console
$ manifest-size https://datasets.datalad.org/dandi/zarr-manifests/zarr-manifests-v2-sorted/001/e3b/001e3b6d-26fb-463f-af28-520a25680ab4/326273bcc8730474323a66ea4e3daa49-113328--97037755426.json
Raw response: 13 818 966 bytes
Parsed response: 18 473 917 bytes
Parsed response: 18 170 616 bytes
```

```console
$ manifest-size --json https://datasets.datalad.org/dandi/zarr-manifests/zarr-manifests-v2-sorted/c7e/25d/c7e25dca-4dc9-4e83-a0d7-5fee56fa8773/c23f15b26134d808b072b8c93b1eeed8-48935--29709893986.json
{
"url": "https://datasets.datalad.org/dandi/zarr-manifests/zarr-manifests-v2-sorted/c7e/25d/c7e25dca-4dc9-4e83-a0d7-5fee56fa8773/c23f15b26134d808b072b8c93b1eeed8-48935--29709893986.json",
"raw_bytes": 5935826,
"parsed_bytes": 7983735
"parsed_bytes": 7867736
}
```

Expand Down
15 changes: 13 additions & 2 deletions src/component.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use get_size::GetSize;
use smartstring::alias::CompactString;
use thiserror::Error;

/// A nonempty path component that does not contain a forward slash or NUL nor
/// equals `.` or `..`
#[derive(Clone, Eq, GetSize, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) struct Component(String);
#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) struct Component(CompactString);

fn validate(s: &str) -> Result<(), ParseComponentError> {
if s.is_empty() {
Expand All @@ -29,6 +30,16 @@ validstr!(
"a plain path component"
);

impl GetSize for Component {
fn get_heap_size(&self) -> usize {
if self.0.is_inline() {
0
} else {
self.0.capacity()
}
}
}

#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
pub(crate) enum ParseComponentError {
#[error("path components cannot be empty")]
Expand Down

0 comments on commit e7ac652

Please sign in to comment.