diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 09a7eae..ca713a5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -66,7 +66,7 @@ jobs: run: git submodule update --init --recursive - name: Test (Release) env: - RUSTFLAGS: "--cfg debug_assertions" + RUSTFLAGS: "-C debug-assertions" run: cargo test --release test-memory: @@ -157,7 +157,8 @@ jobs: - name: Run cargo-tarpaulin uses: actions-rs/tarpaulin@v0.1.3 with: - args: '--features test-allocations -- --test-threads 1' + version: "0.18.0" + args: --features test-allocations --locked -- --test-threads 1 - name: Upload to codecov.io uses: codecov/codecov-action@v4.0.1 with: diff --git a/.gitignore b/.gitignore index 81617f1..b83d222 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1 @@ -# Generated by Cargo -# will have compiled files and executables /target/ - -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock -Cargo.lock -target -Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..ee8f617 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,639 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ciborium" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", +] + +[[package]] +name = "clap" +version = "4.5.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +dependencies = [ + "anstyle", + "clap_lex", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "half" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if", + "crunchy", +] + +[[package]] +name = "hashbrown" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.162" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "oorandom" +version = "11.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" + +[[package]] +name = "plotters" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" + +[[package]] +name = "plotters-svg" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" +dependencies = [ + "plotters-backend", +] + +[[package]] +name = "proc-macro2" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "serde" +version = "1.0.215" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.215" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.132" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "string-interner" +version = "0.17.0" +dependencies = [ + "criterion", + "fxhash", + "hashbrown", + "serde", + "serde_json", +] + +[[package]] +name = "syn" +version = "2.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" + +[[package]] +name = "web-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index 4fdf110..88a8a16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,7 @@ categories = ["data-structures"] edition = "2021" [dependencies] -cfg-if = "1.0" -hashbrown = { version = "0.14.0", default-features = false, features = ["ahash"] } +hashbrown = { version = "0.15.1", default-features = false, features = ["default-hasher", "raw-entry"] } serde = { version = "1.0", default-features = false, features = ["alloc"], optional = true } [dev-dependencies] @@ -28,13 +27,13 @@ name = "bench" harness = false [features] -default = ["std", "serde-1", "inline-more", "backends"] -std = ["serde/std"] +default = ["std", "serde", "inline-more", "backends"] +std = ["serde?/std"] # Enable this if you need `Serde` serialization and deserialization support. # # Enabled by default. -serde-1 = ["serde"] +serde = ["dep:serde"] # Use this to mark more public functions of the StringInterner (and hashbrown) # as inline. This significantly increases compile times of the crate but improves diff --git a/src/backend/bucket/fixed_str.rs b/src/backend/bucket/fixed_str.rs index a9c256c..c3fac0c 100644 --- a/src/backend/bucket/fixed_str.rs +++ b/src/backend/bucket/fixed_str.rs @@ -1,5 +1,4 @@ use super::InternedStr; -#[cfg(not(feature = "std"))] use alloc::string::String; #[derive(Debug, Default, Clone, PartialEq, Eq)] @@ -19,6 +18,8 @@ impl FixedString { /// Returns the underlying [`Box`]. /// /// Guarantees not to perform any reallocations in this process. + /// + /// [`Box`]: alloc::boxed::Box #[inline] pub fn finish(self) -> String { self.contents diff --git a/src/backend/bucket/mod.rs b/src/backend/bucket/mod.rs index e5c95c2..5e5ad48 100644 --- a/src/backend/bucket/mod.rs +++ b/src/backend/bucket/mod.rs @@ -6,9 +6,7 @@ mod interned_str; use self::{fixed_str::FixedString, interned_str::InternedStr}; use super::Backend; use crate::{symbol::expect_valid_symbol, DefaultSymbol, Symbol}; -#[cfg(not(feature = "std"))] -use alloc::string::String; -use alloc::vec::Vec; +use alloc::{string::String, vec::Vec}; use core::{iter::Enumerate, marker::PhantomData, slice}; /// An interner backend that reduces memory allocations by using string buckets. @@ -83,7 +81,8 @@ where S: Symbol, { type Symbol = S; - type Iter<'a> = Iter<'a, S> + type Iter<'a> + = Iter<'a, S> where Self: 'a; diff --git a/src/backend/buffer.rs b/src/backend/buffer.rs index 03f6539..c3b7c0b 100644 --- a/src/backend/buffer.rs +++ b/src/backend/buffer.rs @@ -152,7 +152,8 @@ where S: Symbol, { type Symbol = S; - type Iter<'a> = Iter<'a, S> + type Iter<'a> + = Iter<'a, S> where Self: 'a; @@ -306,10 +307,77 @@ fn decode_var_usize_cold(buffer: &[u8]) -> Option<(usize, usize)> { Some((result, i + 1)) } +impl<'a, S> IntoIterator for &'a BufferBackend +where + S: Symbol, +{ + type Item = (S, &'a str); + type IntoIter = Iter<'a, S>; + + #[cfg_attr(feature = "inline-more", inline)] + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +pub struct Iter<'a, S> { + backend: &'a BufferBackend, + remaining: usize, + next: usize, +} + +impl<'a, S> Iter<'a, S> { + #[cfg_attr(feature = "inline-more", inline)] + pub fn new(backend: &'a BufferBackend) -> Self { + Self { + backend, + remaining: backend.len_strings, + next: 0, + } + } +} + +impl<'a, S> Iterator for Iter<'a, S> +where + S: Symbol, +{ + type Item = (S, &'a str); + + #[inline] + fn size_hint(&self) -> (usize, Option) { + let remaining = self.len(); + (remaining, Some(remaining)) + } + + #[inline] + fn next(&mut self) -> Option { + self.backend + .resolve_index_to_str(self.next) + .and_then(|(bytes, next)| { + // SAFETY: Within the iterator all indices given to `resolv_index_to_str` + // are properly pointing to the start of each interned string. + let string = unsafe { str::from_utf8_unchecked(bytes) }; + let symbol = S::try_from_usize(self.next)?; + self.next = next; + self.remaining -= 1; + Some((symbol, string)) + }) + } +} + +impl ExactSizeIterator for Iter<'_, S> +where + S: Symbol, +{ + #[inline] + fn len(&self) -> usize { + self.remaining + } +} + #[cfg(test)] mod tests { use super::{decode_var_usize, encode_var_usize}; - #[cfg(not(feature = "std"))] use alloc::vec::Vec; #[test] @@ -335,7 +403,7 @@ mod tests { } #[test] - #[cfg_attr(any(miri, tarpaulin), ignore)] + #[cfg_attr(any(miri), ignore)] fn encode_var_usize_3_bytes_works() { let mut buffer = Vec::new(); for i in 2usize.pow(14)..2usize.pow(21) { @@ -354,7 +422,7 @@ mod tests { } /// Allows to split up the test into multiple fragments that can run in parallel. - #[cfg_attr(any(miri, tarpaulin), ignore)] + #[cfg_attr(any(miri), ignore)] fn assert_encode_var_usize_4_bytes(range: core::ops::Range) { let mut buffer = Vec::new(); for i in range { @@ -374,25 +442,25 @@ mod tests { } #[test] - #[cfg_attr(any(miri, tarpaulin), ignore)] + #[cfg_attr(any(miri), ignore)] fn encode_var_usize_4_bytes_01_works() { assert_encode_var_usize_4_bytes(2usize.pow(21)..2usize.pow(24)); } #[test] - #[cfg_attr(any(miri, tarpaulin), ignore)] + #[cfg_attr(any(miri), ignore)] fn encode_var_usize_4_bytes_02_works() { assert_encode_var_usize_4_bytes(2usize.pow(24)..2usize.pow(26)); } #[test] - #[cfg_attr(any(miri, tarpaulin), ignore)] + #[cfg_attr(any(miri), ignore)] fn encode_var_usize_4_bytes_03_works() { assert_encode_var_usize_4_bytes(2usize.pow(26)..2usize.pow(27)); } #[test] - #[cfg_attr(any(miri, tarpaulin), ignore)] + #[cfg_attr(any(miri), ignore)] fn encode_var_usize_4_bytes_04_works() { assert_encode_var_usize_4_bytes(2usize.pow(27)..2usize.pow(28)); } @@ -433,71 +501,3 @@ mod tests { // ); } } - -impl<'a, S> IntoIterator for &'a BufferBackend -where - S: Symbol, -{ - type Item = (S, &'a str); - type IntoIter = Iter<'a, S>; - - #[cfg_attr(feature = "inline-more", inline)] - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -} - -pub struct Iter<'a, S> { - backend: &'a BufferBackend, - remaining: usize, - next: usize, -} - -impl<'a, S> Iter<'a, S> { - #[cfg_attr(feature = "inline-more", inline)] - pub fn new(backend: &'a BufferBackend) -> Self { - Self { - backend, - remaining: backend.len_strings, - next: 0, - } - } -} - -impl<'a, S> Iterator for Iter<'a, S> -where - S: Symbol, -{ - type Item = (S, &'a str); - - #[inline] - fn size_hint(&self) -> (usize, Option) { - let remaining = self.len(); - (remaining, Some(remaining)) - } - - #[inline] - fn next(&mut self) -> Option { - self.backend - .resolve_index_to_str(self.next) - .and_then(|(bytes, next)| { - // SAFETY: Within the iterator all indices given to `resolv_index_to_str` - // are properly pointing to the start of each interned string. - let string = unsafe { str::from_utf8_unchecked(bytes) }; - let symbol = S::try_from_usize(self.next)?; - self.next = next; - self.remaining -= 1; - Some((symbol, string)) - }) - } -} - -impl<'a, S> ExactSizeIterator for Iter<'a, S> -where - S: Symbol, -{ - #[inline] - fn len(&self) -> usize { - self.remaining - } -} diff --git a/src/backend/string.rs b/src/backend/string.rs index 42b0a12..307dd60 100644 --- a/src/backend/string.rs +++ b/src/backend/string.rs @@ -137,7 +137,7 @@ where /// If the backend ran out of symbols. fn push_string(&mut self, string: &str) -> S { self.buffer.push_str(string); - let to = self.buffer.as_bytes().len(); + let to = self.buffer.len(); let symbol = self.next_symbol(); self.ends.push(to); symbol @@ -149,7 +149,8 @@ where S: Symbol, { type Symbol = S; - type Iter<'a> = Iter<'a, S> + type Iter<'a> + = Iter<'a, S> where Self: 'a; diff --git a/src/interner.rs b/src/interner.rs index db01de1..3841a47 100644 --- a/src/interner.rs +++ b/src/interner.rs @@ -5,7 +5,7 @@ use core::{ hash::{BuildHasher, Hash, Hasher}, iter::FromIterator, }; -use hashbrown::{hash_map::DefaultHashBuilder, HashMap}; +use hashbrown::{DefaultHashBuilder, HashMap}; /// Creates the `u64` hash value for the given value using the given hash builder. fn make_hash(builder: &impl BuildHasher, value: &T) -> u64 diff --git a/src/lib.rs b/src/lib.rs index 06ea97c..8f313a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ -#![doc(html_root_url = "https://docs.rs/crate/string-interner/0.12.0")] -#![cfg_attr(not(feature = "std"), no_std)] -// #![deny(missing_docs)] +#![no_std] +#![doc(html_root_url = "https://docs.rs/crate/string-interner/0.18.0")] #![warn(unsafe_op_in_unsafe_fn, clippy::redundant_closure_for_method_calls)] //! Caches strings efficiently, with minimal memory footprint and associates them with unique symbols. @@ -119,12 +118,12 @@ //! However, all this is at the costs of a less efficient resolution of symbols. //! Note that the symbols generated by the `BufferBackend` are not contiguous. -#[cfg(not(feature = "std"))] extern crate alloc; #[cfg(feature = "std")] -extern crate std as alloc; +#[macro_use] +extern crate std; -#[cfg(feature = "serde-1")] +#[cfg(feature = "serde")] mod serde_impl; pub mod backend; @@ -146,4 +145,4 @@ pub use self::{ }; #[doc(inline)] -pub use hashbrown::hash_map::DefaultHashBuilder; +pub use hashbrown::DefaultHashBuilder; diff --git a/src/serde_impl.rs b/src/serde_impl.rs index 9ca51b3..0bf79fb 100644 --- a/src/serde_impl.rs +++ b/src/serde_impl.rs @@ -1,5 +1,4 @@ use crate::{backend::Backend, StringInterner, Symbol}; -#[cfg(not(feature = "std"))] use alloc::boxed::Box; use core::{default::Default, fmt, hash::BuildHasher, marker}; use serde::{ diff --git a/tests/allocator.rs b/tests/allocator.rs index a5bb108..af4dfc6 100644 --- a/tests/allocator.rs +++ b/tests/allocator.rs @@ -9,6 +9,7 @@ pub struct TracingAllocator { } impl TracingAllocator { + #[allow(clippy::new_without_default)] // not applicable here pub const fn new() -> Self { Self { inner: System, @@ -36,8 +37,7 @@ impl TracingAllocator { unsafe impl GlobalAlloc for TracingAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { self.stats.push_allocations(layout); - let res = self.inner.alloc(layout); - res + self.inner.alloc(layout) } unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {