Skip to content

Commit

Permalink
Merge pull request #1401 from dtolnay/foldhash
Browse files Browse the repository at this point in the history
Switch C++ std::hash<T> implementations to foldhash
  • Loading branch information
dtolnay authored Nov 16, 2024
2 parents f3cd913 + cf9f18a commit 547a0ed
Show file tree
Hide file tree
Showing 21 changed files with 179 additions and 252 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rust: [nightly, beta, stable, 1.82.0, 1.74.0, 1.71.0]
rust: [nightly, beta, stable, 1.82.0, 1.74.0, 1.73.0]
os: [ubuntu]
include:
- name: Cargo on macOS
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
# builds.
run: |
echo RUSTFLAGS=$RUSTFLAGS >> $GITHUB_ENV
echo exclude=--exclude cxx-test-suite ${{matrix.rust == '1.71.0' && '--exclude cxxbridge-cmd' || ''}} >> $GITHUB_OUTPUT
echo exclude=--exclude cxx-test-suite ${{matrix.rust == '1.73.0' && '--exclude cxxbridge-cmd' || ''}} >> $GITHUB_OUTPUT
env:
RUSTFLAGS: ${{env.RUSTFLAGS}} ${{matrix.os != 'ubuntu' && github.event_name != 'schedule' && '--cfg skip_ui_tests' || ''}}
id: testsuite
Expand Down
1 change: 1 addition & 0 deletions BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rust_library(
deps = [
":core",
":cxxbridge-macro",
"//third-party:foldhash",
],
)

Expand Down
5 changes: 4 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ rust_library(
":cxxbridge-macro",
],
visibility = ["//visibility:public"],
deps = [":core-lib"],
deps = [
":core-lib",
"@crates.io//:foldhash",
],
)

alias(
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ keywords = ["ffi", "c++"]
license = "MIT OR Apache-2.0"
links = "cxxbridge1"
repository = "https://github.com/dtolnay/cxx"
rust-version = "1.71"
rust-version = "1.73"

[features]
default = ["std", "cxxbridge-flags/default"] # c++11
"c++14" = ["cxxbridge-flags/c++14"]
"c++17" = ["cxxbridge-flags/c++17"]
"c++20" = ["cxxbridge-flags/c++20"]
alloc = []
std = ["alloc"]
std = ["alloc", "foldhash/std"]

[dependencies]
cxxbridge-macro = { version = "=1.0.130", path = "macro" }
foldhash = { version = "0.1", default-features = false }
link-cplusplus = "1.0.9"

[build-dependencies]
Expand Down
20 changes: 19 additions & 1 deletion MODULE.bazel.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cxx = "1.0"
cxx-build = "1.0"
```

*Compiler support: requires rustc 1.71+ and c++11 or newer*<br>
*Compiler support: requires rustc 1.73+ and c++11 or newer*<br>
*[Release notes](https://github.com/dtolnay/cxx/releases)*

<br>
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn main() {
println!("cargo:rustc-check-cfg=cfg(skip_ui_tests)");
}

if rustc.minor < 71 {
println!("cargo:warning=The cxx crate requires a rustc version 1.71.0 or newer.");
if rustc.minor < 73 {
println!("cargo:warning=The cxx crate requires a rustc version 1.73.0 or newer.");
println!(
"cargo:warning=You appear to be building with: {}",
rustc.version,
Expand Down
2 changes: 1 addition & 1 deletion flags/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description = "Compiler configuration of the `cxx` crate (implementation detail)
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/cxx"
rust-version = "1.71"
rust-version = "1.73"

[features]
default = [] # c++11
Expand Down
2 changes: 1 addition & 1 deletion gen/build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ homepage = "https://cxx.rs"
keywords = ["ffi", "build-dependencies"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/cxx"
rust-version = "1.71"
rust-version = "1.73"

[features]
parallel = ["cc/parallel"]
Expand Down
2 changes: 1 addition & 1 deletion gen/cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ homepage = "https://cxx.rs"
keywords = ["ffi"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/cxx"
rust-version = "1.71"
rust-version = "1.73"

[[bin]]
name = "cxxbridge"
Expand Down
2 changes: 1 addition & 1 deletion gen/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exclude = ["build.rs"]
keywords = ["ffi"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/cxx"
rust-version = "1.71"
rust-version = "1.73"

[dependencies]
codespan-reporting = "0.11.1"
Expand Down
2 changes: 1 addition & 1 deletion macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ homepage = "https://cxx.rs"
keywords = ["ffi"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/cxx"
rust-version = "1.71"
rust-version = "1.73"

[lib]
proc-macro = true
Expand Down
10 changes: 2 additions & 8 deletions src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use core::hash::{Hash, Hasher};
use core::hash::{BuildHasher as _, Hash};

#[doc(hidden)]
pub fn hash<V: Hash>(value: &V) -> usize {
#[cfg(feature = "std")]
let mut hasher = std::collections::hash_map::DefaultHasher::new();
#[cfg(not(feature = "std"))]
let mut hasher = crate::sip::SipHasher13::new();

Hash::hash(value, &mut hasher);
Hasher::finish(&hasher) as usize
foldhash::quality::FixedState::default().hash_one(value) as usize
}
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//!
//! <br>
//!
//! *Compiler support: requires rustc 1.71+ and c++11 or newer*<br>
//! *Compiler support: requires rustc 1.73+ and c++11 or newer*<br>
//! *[Release notes](https://github.com/dtolnay/cxx/releases)*
//!
//! <br>
Expand Down Expand Up @@ -466,7 +466,6 @@ mod rust_string;
mod rust_type;
mod rust_vec;
mod shared_ptr;
mod sip;
#[path = "cxx_string.rs"]
mod string;
mod symbols;
Expand Down
Loading

0 comments on commit 547a0ed

Please sign in to comment.