Skip to content

Commit

Permalink
Make dependency on 'time' optional
Browse files Browse the repository at this point in the history
Resolves the issue of needing an upper-bound on its version in order
to support Rust 1.63: #36
  • Loading branch information
progval committed Mar 10, 2024
1 parent b25d761 commit 518c3b3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- nightly

features:
- ''
- '--all-features'
- '--no-default-features'

steps:
Expand Down Expand Up @@ -97,13 +97,6 @@ jobs:
profile: minimal
override: true

- name: downgrade 'time' for Rust 1.63.0
uses: actions-rs/cargo@v1
with:
command: update
args: --package time --precise 0.3.20
if: ${{ matrix.rust == '1.63.0' }}

- name: Build generator
uses: actions-rs/cargo@v1
with:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ default = []

unstable = []
no_std = []
generator-timing = ["unicode_names2_generator/timing"]

[dev-dependencies.unicode_names2_macros]
path = "unicode_names2_macros"
Expand Down
4 changes: 3 additions & 1 deletion generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ Generates the perfect-hash function used by `unicode_names2`.

[features]
unstable = []
default = []
timing = ["time"]

[dependencies]
time = "0.3,<0.3.21"
time = { version = "0.3", optional = true }
log = "0"
getopts = "0.2.21"
rand = "0.8.5"
Expand Down
6 changes: 6 additions & 0 deletions generator/src/phf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,20 @@ pub fn create_phf(
max_tries: usize,
) -> (u64, Vec<(u32, u32)>, Vec<char>) {
let mut rng = StdRng::seed_from_u64(0xf0f0f0f0);
#[cfg(feature = "timing")]
let start = time::Instant::now();

for i in 0..(max_tries) {
#[cfg(feature = "timing")]
let my_start = time::Instant::now();
#[cfg(feature = "timing")]
println!("PHF #{}: starting {:.2}", i, my_start - start);
#[cfg(not(feature = "timing"))]
println!("PHF #{}", i);

let seed = rng.gen();
if let Some((disp, map)) = try_phf_table(data, lambda, seed, &mut rng) {
#[cfg(feature = "timing")]
println!(
"PHF took: total {:.2} s, successive {:.2} s",
start.elapsed(),
Expand Down

0 comments on commit 518c3b3

Please sign in to comment.