Skip to content
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
23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ categories = ["caching", "data-structures"]
travis-ci = { repository = "anderslanglands/ustr", branch = "master" }

[dependencies]
byteorder = "1.5"
lazy_static = "1.5"
parking_lot = "0.12"
serde = { version = "1", optional = true }
ahash = { version = "0.8.3", default-features = false }
byteorder = "1.4.3"
lazy_static = "1.4.0"
parking_lot = "0.12.1"
serde = { version = "1.0", optional = true }


[dev-dependencies]
criterion = "0.4.0"
crossbeam-channel = "0.5.0"
crossbeam-utils = "0.8.1"
libc = "0.2.62"
serde_json = "1.0"
string-interner = "0.13.0"
string_cache = "0.8.1"
criterion = "0.4"
crossbeam-channel = "0.5"
crossbeam-utils = "0.8"
libc = "0.2"
serde_json = "1"
string-interner = "0.13"
string_cache = "0.8"

[[bench]]
name = "creation"
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ is directy ported from OIIO.
use ustr::{Ustr, ustr};

// Creation is quick and easy using either `Ustr::from` or the `ustr` short
// function and only one copy of any string is stored
// function and only one copy of any string is stored.
let h1 = Ustr::from("hello");
let h2 = ustr("hello");

// Comparisons and copies are extremely cheap
// Comparisons and copies are extremely cheap.
let h3 = h1;
assert_eq!(h2, h3);

// You can pass straight to FFI
// You can pass straight to FFI.
let len = unsafe {
libc::strlen(h1.as_char_ptr())
};
Expand All @@ -58,7 +58,7 @@ assert_eq!(len, 5);
// the UstrMap and UstrSet exports:
use ustr::UstrMap;

// Key type is always Ustr
// Key type is always Ustr.
let mut map: UstrMap<usize> = UstrMap::default();
map.insert(u1, 17);
assert_eq!(*map.get(&u1).unwrap(), 17);
Expand Down Expand Up @@ -100,7 +100,8 @@ If you are writing a library that uses ustr and want users to be able to create
## Changelog

### Changes since 0.10
* Actually renamed use of "serialization" feature to "serde"

* Actually renamed `serialization` feature to `serde`

### Changes since 0.9

Expand Down Expand Up @@ -334,11 +335,11 @@ I use it regularly on 64-bit systems, and it has passed Miri on a 32-bit system
as well, bit 32-bit is not checked regularly. If you want to use it on 32-bit,
please make sure to run Miri and open and issue if you find any problems.

## Licence
## License

BSD+ License

Copyright © 2019—2020 Anders Langlands
Copyright © 2019—2024 Anders Langlands

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -387,9 +388,10 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Contains code ported from [OpenImageIO](https://github.com/OpenImageIO/oiio),
BSD 3-clause licence.
BSD 3-clause license.

Contains a copy of Max Woolf's [Big List of Naughty Strings](https://github.com/minimaxir/big-list-of-naughty-strings), MIT licence.
Contains a copy of Max Woolf's [Big List of Naughty Strings](https://github.com/minimaxir/big-list-of-naughty-strings),
MIT license.

Contains some strings from
[SecLists](https://github.com/danielmiessler/SecLists), MIT licence.
[SecLists](https://github.com/danielmiessler/SecLists), MIT license.
3 changes: 0 additions & 3 deletions benches/creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use string_interner::StringInterner;

use ustr::*;

#[cfg(not(feature = "spinlock"))]
use parking_lot::Mutex;
#[cfg(feature = "spinlock")]
use spin::Mutex;

fn criterion_benchmark(c: &mut Criterion) {
let path =
Expand Down
9 changes: 5 additions & 4 deletions src/bumpalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ impl LeakyBumpAlloc {

// Allocates a new chunk. Aborts if out of memory.
pub unsafe fn allocate(&mut self, num_bytes: usize) -> *mut u8 {
// our new ptr will be offset down the heap by num_bytes bytes
// Our new ptr will be offset down the heap by num_bytes bytes.
let ptr = self.ptr as usize;
let new_ptr = ptr.checked_sub(num_bytes).expect("ptr sub overflowed");
// round down to alignment
// Round down to alignment.
let new_ptr = new_ptr & !(self.layout.align() - 1);
//check we have enough capacity
// Check we have enough capacity.
let start = self.start as usize;
if new_ptr < start {
eprintln!(
"Allocator asked to bump to {} bytes with a capacity of {}",
self.end as usize - new_ptr,
self.capacity()
);
// we have to abort here rather than panic or the mutex may deadlock
// We have to abort here rather than panic or the mutex may
// deadlock.
std::process::abort();
}

Expand Down
13 changes: 8 additions & 5 deletions src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use super::Ustr;
use byteorder::{ByteOrder, NativeEndian};
use std::collections::{HashMap, HashSet};
use std::hash::{BuildHasherDefault, Hasher};
use std::{
collections::{HashMap, HashSet},
hash::{BuildHasherDefault, Hasher},
};

/// A standard `HashMap` using `Ustr` as the key type with a custom `Hasher`
/// that just uses the precomputed hash for speed instead of calculating it
/// that just uses the precomputed hash for speed instead of calculating it.
pub type UstrMap<V> = HashMap<Ustr, V, BuildHasherDefault<IdentityHasher>>;

/// A standard `HashSet` using `Ustr` as the key type with a custom `Hasher`
/// that just uses the precomputed hash for speed instead of calculating it
/// that just uses the precomputed hash for speed instead of calculating it.
pub type UstrSet = HashSet<Ustr, BuildHasherDefault<IdentityHasher>>;

/// The worst hasher in the world - the identity hasher.
/// The worst hasher in the world -- the identity hasher.
#[doc(hidden)]
#[derive(Default)]
pub struct IdentityHasher {
Expand Down
Loading