Skip to content

Commit f66a132

Browse files
authored
Merge pull request #13 from billyevans/rust_2024
Migrate to rust 2024 edition
2 parents 6e6e694 + 8d104e3 commit f66a132

File tree

5 files changed

+74
-47
lines changed

5 files changed

+74
-47
lines changed

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[package]
22

33
name = "tst"
4-
version = "0.11.0"
4+
version = "0.12.0"
55

66
authors = ["Alexey Pervushin <[email protected]>"]
7-
edition = "2021"
7+
edition = "2024"
88
readme = "README.md"
99
license = "MIT"
1010
description = "Ternary search trie collection in rust with similar API to std::collections as it possible"
@@ -20,3 +20,8 @@ libc = "0.2.*"
2020
rand = "0.6.*"
2121
jemallocator = "0.1.*"
2222
jemalloc-sys = "0.1.*"
23+
criterion = "0.6"
24+
25+
[[bench]]
26+
name = "bench"
27+
harness = false

benches/bench.rs

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
#![cfg(test)]
2-
#![feature(test)]
3-
extern crate test;
4-
5-
extern crate tst;
6-
use self::tst::TSTMap;
7-
use self::test::Bencher;
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
use tst::TSTMap;
83
use std::str;
94

105
fn prepare() -> TSTMap<i32> {
@@ -24,49 +19,76 @@ fn prepare() -> TSTMap<i32> {
2419
m
2520
}
2621

27-
#[bench]
28-
fn insert_same(b: &mut Bencher) {
29-
let mut m = prepare();
30-
31-
let mut k = 100;
32-
b.iter(|| {
33-
m.insert("abcabcabca", k);
34-
k += 1;
22+
fn insert_same(c: &mut Criterion) {
23+
c.bench_function("insert_same", |b| {
24+
b.iter_with_setup(
25+
|| {
26+
let m = prepare();
27+
let k = 100;
28+
(m, k)
29+
},
30+
|(mut m, mut k)| {
31+
m.insert("abcabcabca", k);
32+
k += 1;
33+
std::hint::black_box((m, k))
34+
}
35+
);
3536
});
3637
}
3738

38-
#[bench]
39-
fn get_same(b: &mut Bencher) {
40-
let m = prepare();
41-
42-
b.iter(|| {
43-
m.get("abcabcabca");
39+
fn get_same(c: &mut Criterion) {
40+
c.bench_function("get_same", |b| {
41+
b.iter_with_setup(
42+
|| prepare(),
43+
|m| {
44+
std::hint::black_box(m.get("abcabcabca"));
45+
}
46+
);
4447
});
4548
}
4649

47-
#[bench]
48-
fn remove_same(b: &mut Bencher) {
49-
let mut m = prepare();
50-
51-
b.iter(|| {
52-
m.remove("abcabcabca");
50+
fn remove_same(c: &mut Criterion) {
51+
c.bench_function("remove_same", |b| {
52+
b.iter_with_setup(
53+
|| prepare(),
54+
|mut m| {
55+
std::hint::black_box(m.remove("abcabcabca"));
56+
}
57+
);
5358
});
5459
}
5560

56-
#[bench]
57-
fn get_none(b: &mut Bencher) {
58-
let m = prepare();
59-
b.iter(|| {
60-
m.get("abcabcabcad");
61+
fn get_none(c: &mut Criterion) {
62+
c.bench_function("get_none", |b| {
63+
b.iter_with_setup(
64+
|| prepare(),
65+
|m| {
66+
std::hint::black_box(m.get("abcabcabcad"));
67+
}
68+
);
6169
});
6270
}
6371

64-
#[bench]
65-
fn iterate(b: &mut Bencher) {
66-
let m = prepare();
67-
b.iter(|| {
68-
for x in m.iter() {
69-
test::black_box(x);
70-
}
72+
fn iterate(c: &mut Criterion) {
73+
c.bench_function("iterate", |b| {
74+
b.iter_with_setup(
75+
|| prepare(),
76+
|m| {
77+
for x in m.iter() {
78+
std::hint::black_box(x);
79+
}
80+
}
81+
);
7182
});
7283
}
84+
85+
criterion_group!(
86+
benches,
87+
insert_same,
88+
get_same,
89+
remove_same,
90+
get_none,
91+
iterate
92+
);
93+
94+
criterion_main!(benches);

examples/dict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
55

66
extern crate libc;
77
//extern {fn __rjem_je_stats_print (write_cb: extern fn (*const libc::c_void, *const libc::c_char), cbopaque: *const libc::c_void, opts: *const libc::c_char);}
8-
extern fn write_cb (_: *mut libc::c_void, message: *const libc::c_char) {
8+
extern "C" fn write_cb (_: *mut libc::c_void, message: *const libc::c_char) {
99
print! ("{}", String::from_utf8_lossy (unsafe {std::ffi::CStr::from_ptr (message as *const i8) .to_bytes()}));}
1010
extern crate jemalloc_sys;
1111

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ macro_rules! tstmap {
2424
$crate::TSTMap::new()
2525
}};
2626
// trailing comma case
27-
($($key:expr => $value:expr,)+) => (tstmap!($($key => $value),+));
28-
($( $key: expr => $val: expr ),*) => {{
27+
($($key:expr_2021 => $value:expr_2021,)+) => (tstmap!($($key => $value),+));
28+
($( $key: expr_2021 => $val: expr_2021 ),*) => {{
2929
let mut m = $crate::TSTMap::new();
3030
$(
3131
m.insert($key, $val);
@@ -60,8 +60,8 @@ macro_rules! tstset {
6060
$crate::TSTSet::new()
6161
}};
6262
// trailing comma case
63-
($($key:expr,)+) => (tstset!($($key),+));
64-
($($key: expr),*) => {{
63+
($($key:expr_2021,)+) => (tstset!($($key),+));
64+
($($key: expr_2021),*) => {{
6565
let mut s = $crate::TSTSet::new();
6666
$(
6767
s.insert($key);

src/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ impl<Value> Drop for TSTMap<Value> {
516516
fn drop(&mut self) {
517517
let root = self.root.take();
518518
let mut iter = DropTraverse::new(root);
519-
for _ in iter.next() { }
519+
while let Some(_) = iter.next() { }
520520
}
521521
}
522522

0 commit comments

Comments
 (0)