Skip to content

Commit

Permalink
Fix clippy issues, resolve tech debt (#60)
Browse files Browse the repository at this point in the history
* fix clippy issue

* remove compat.rs file

Use alloc crate dependencies directly instead.

* update criterion
  • Loading branch information
Robbepop authored Feb 6, 2024
1 parent fa65c81 commit d2beb90
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ serde = { version = "1.0", default-features = false, features = ["alloc"], optio

[dev-dependencies]
serde_json = "1.0"
criterion = "0.3"
criterion = "0.5.1"
fxhash = "0.2"

[[bench]]
Expand Down
4 changes: 3 additions & 1 deletion src/backend/bucket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ mod interned_str;

use self::{fixed_str::FixedString, interned_str::InternedStr};
use super::Backend;
use crate::{compat::Vec, symbol::expect_valid_symbol, DefaultSymbol, Symbol};
use crate::{symbol::expect_valid_symbol, DefaultSymbol, Symbol};
#[cfg(not(feature = "std"))]
use alloc::string::String;
use alloc::vec::Vec;
use core::{iter::Enumerate, marker::PhantomData, slice};

/// An interner backend that reduces memory allocations by using string buckets.
///
/// # Note
Expand Down
3 changes: 2 additions & 1 deletion src/backend/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![cfg(feature = "backends")]

use super::Backend;
use crate::{compat::Vec, symbol::expect_valid_symbol, DefaultSymbol, Symbol};
use crate::{symbol::expect_valid_symbol, DefaultSymbol, Symbol};
use alloc::vec::Vec;
use core::{marker::PhantomData, mem, str};

/// An interner backend that appends all interned string information in a single buffer.
Expand Down
8 changes: 2 additions & 6 deletions src/backend/simple.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#![cfg(feature = "backends")]

use super::Backend;
use crate::{
compat::{Box, ToString, Vec},
symbol::expect_valid_symbol,
DefaultSymbol,
Symbol,
};
use crate::{symbol::expect_valid_symbol, DefaultSymbol, Symbol};
use alloc::{boxed::Box, string::ToString, vec::Vec};
use core::{iter::Enumerate, marker::PhantomData, slice};

/// A simple backend that stores a separate allocation for every interned string.
Expand Down
8 changes: 2 additions & 6 deletions src/backend/string.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#![cfg(feature = "backends")]

use super::Backend;
use crate::{
compat::{String, Vec},
symbol::expect_valid_symbol,
DefaultSymbol,
Symbol,
};
use crate::{symbol::expect_valid_symbol, DefaultSymbol, Symbol};
use alloc::{string::String, vec::Vec};
use core::{iter::Enumerate, marker::PhantomData, slice};

/// An interner backend that accumulates all interned string contents into one string.
Expand Down
27 changes: 0 additions & 27 deletions src/compat.rs

This file was deleted.

11 changes: 3 additions & 8 deletions src/interner.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
use crate::{
backend::Backend,
compat::{DefaultHashBuilder, HashMap},
DefaultBackend,
DefaultSymbol,
Symbol,
};
use crate::{backend::Backend, DefaultBackend, DefaultSymbol, Symbol};
use core::{
fmt,
fmt::{Debug, Formatter},
hash::{BuildHasher, Hash, Hasher},
iter::FromIterator,
};
use hashbrown::{hash_map::DefaultHashBuilder, HashMap};

/// Creates the `u64` hash value for the given value using the given hash builder.
fn make_hash<T>(builder: &impl BuildHasher, value: &T) -> u64
Expand Down Expand Up @@ -215,7 +210,7 @@ where
// we receive from our backend making them valid.
string == unsafe { backend.resolve_unchecked(*symbol) }
});
use crate::compat::hash_map::RawEntryMut;
use hashbrown::hash_map::RawEntryMut;
let (&mut symbol, &mut ()) = match entry {
RawEntryMut::Occupied(occupied) => occupied.into_key_value(),
RawEntryMut::Vacant(vacant) => {
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,23 @@
//! Never use this one for real use cases!

#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std as alloc;

#[cfg(feature = "serde-1")]
mod serde_impl;

pub mod backend;
mod compat;
mod interner;
pub mod symbol;

#[doc(inline)]
pub use self::{
backend::DefaultBackend,
compat::DefaultHashBuilder,
interner::StringInterner,
symbol::{DefaultSymbol, Symbol},
};
#[doc(inline)]
pub use hashbrown::hash_map::DefaultHashBuilder;

0 comments on commit d2beb90

Please sign in to comment.