Skip to content

Adapt to new jbk SmallVec #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion libwaj/src/create/entry_store_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl EntryStoreCreator {
//println!("{:?}", entry.name());
let entry = match entry_kind {
EntryKind::Content(content_address, mimetype) => {
let mime_id = self.mime_store.add_value(mimetype.to_string().into());
let mime_id = self.mime_store.add_value(mimetype.as_ref().as_bytes());
Entry::new_content(path, mime_id, content_address)
}
EntryKind::Redirect(target) => {
Expand Down
18 changes: 9 additions & 9 deletions libwaj/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ use jbk::reader::ByteSlice;

pub struct CommonPart {
idx: jbk::EntryIdx,
path: Vec<u8>,
path: jbk::SmallBytes,
}

pub trait CommonEntry {
fn common(&self) -> &CommonPart;
fn idx(&self) -> jbk::EntryIdx {
self.common().idx
}
fn path(&self) -> &Vec<u8> {
fn path(&self) -> &[u8] {
&self.common().path
}
}

pub struct Content {
common: CommonPart,
mimetype: Vec<u8>,
mimetype: jbk::SmallBytes,
content: jbk::ContentAddress,
}

Expand All @@ -34,14 +34,14 @@ impl Content {
self.content
}

pub fn mimetype(&self) -> &Vec<u8> {
pub fn mimetype(&self) -> &[u8] {
&self.mimetype
}
}

pub struct Redirect {
common: CommonPart,
target: Vec<u8>,
target: jbk::SmallBytes,
}

impl CommonEntry for Redirect {
Expand All @@ -51,7 +51,7 @@ impl CommonEntry for Redirect {
}

impl Redirect {
pub fn target(&self) -> &Vec<u8> {
pub fn target(&self) -> &[u8] {
&self.target
}
}
Expand All @@ -71,7 +71,7 @@ mod private {

fn create_entry(&self, idx: jbk::EntryIdx, reader: &ByteSlice) -> jbk::Result<CommonPart> {
let path_prop = self.path_property.create(reader)?;
let mut path = vec![];
let mut path = jbk::SmallBytes::new();
path_prop.resolve_to_vec(&mut path)?;
Ok(CommonPart { idx, path })
}
Expand All @@ -96,7 +96,7 @@ mod private {

fn create_entry(&self, idx: jbk::EntryIdx, reader: &ByteSlice) -> jbk::Result<Self::Entry> {
let mimetype_prop = self.mimetype_property.create(reader)?;
let mut mimetype = vec![];
let mut mimetype = jbk::SmallBytes::new();
mimetype_prop.resolve_to_vec(&mut mimetype)?;
Ok(Content {
common: self.common.create_entry(idx, reader)?,
Expand Down Expand Up @@ -124,7 +124,7 @@ mod private {
fn create_entry(&self, idx: jbk::EntryIdx, reader: &ByteSlice) -> jbk::Result<Self::Entry> {
let common = self.common.create_entry(idx, reader)?;
let target_prop = self.link_property.create(reader)?;
let mut target = vec![];
let mut target = jbk::SmallBytes::new();
target_prop.resolve_to_vec(&mut target)?;
Ok(Redirect { common, target })
}
Expand Down
6 changes: 3 additions & 3 deletions libwaj/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn url_variants(url: &str) -> Vec<Cow<str>> {

struct ContentEntry {
pub content_address: jbk::reader::ContentAddress,
pub mimetype: Vec<u8>,
pub mimetype: jbk::SmallBytes,
}

struct ContentBuilder {
Expand Down Expand Up @@ -70,7 +70,7 @@ struct RedirectBuilder {
}

impl Builder for RedirectBuilder {
type Entry = Vec<u8>;
type Entry = jbk::SmallBytes;

fn new(properties: &AllProperties) -> Self {
Self {
Expand All @@ -80,7 +80,7 @@ impl Builder for RedirectBuilder {

fn create_entry(&self, _idx: jbk::EntryIdx, reader: &ByteSlice) -> jbk::Result<Self::Entry> {
let target_prop = self.target_property.create(reader)?;
let mut target = vec![];
let mut target = jbk::SmallBytes::new();
target_prop.resolve_to_vec(&mut target)?;
Ok(target)
}
Expand Down
4 changes: 2 additions & 2 deletions libwaj/src/waj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct PathBuilder {
}

impl Builder for PathBuilder {
type Entry = Vec<u8>;
type Entry = jbk::SmallBytes;

fn new(properties: &AllProperties) -> Self {
Self {
Expand All @@ -43,7 +43,7 @@ impl Builder for PathBuilder {

fn create_entry(&self, _idx: jbk::EntryIdx, reader: &ByteSlice) -> jbk::Result<Self::Entry> {
let path_prop = self.path_property.create(reader)?;
let mut path = vec![];
let mut path = jbk::SmallBytes::new();
path_prop.resolve_to_vec(&mut path)?;
Ok(path)
}
Expand Down