Feat: Add CheetahBytes byte semantics#121
Conversation
|
Warning Review limit reached
More reviews will be available in 52 minutes and 57 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (22)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9e13e7f to
623dd3d
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a dedicated CheetahBytes type (behind the bytes feature) to separate byte-oriented semantics from CheetahString, while also updating substring search to use memchr/memmem and tightening UTF-8 construction paths for CheetahString.
Changes:
- Add
CheetahByteswith explicit checked (TryFrom/try_into_string) and unsafe (into_string_unchecked) conversion intoCheetahString, plus byte-oriented serde semantics. - Remove implicit byte-to-string conversions for
CheetahString(replaceFromwithTryFromand add explicit unsafe constructors), and update serde forCheetahStringto serialize as a string. - Introduce
memchr-based substring search utilities (find/rfind) and add new tests/benches plus CI artifact capture for layout snapshots.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
Cargo.toml |
Makes bytes optional, adds memchr, bumps crate version, adds benches/dev-dep. |
src/lib.rs |
Wires in search module, conditionally adds/exports CheetahBytes, exports CheetahFinder. |
src/cheetah_string.rs |
Removes implicit byte conversions, adds checked/unsafe UTF-8 constructors, updates search + builder/mutation paths. |
src/bytes.rs |
New CheetahBytes type with conversions and (feature-gated) serde bytes behavior. |
src/search.rs |
New memchr/memmem-based find_bytes/rfind_bytes and reusable CheetahFinder. |
src/serde.rs |
Moves CheetahString serde to string-only serialization; updates UTF-8 validation in visitor paths. |
src/simd.rs |
Marks now-unused SIMD search helpers as dead_code to avoid warnings. |
tests/basic.rs |
Updates tests to use checked byte conversions and adjusts ARC/Vec buffer reuse expectations. |
tests/bytes.rs |
Adds CheetahBytes tests for invalid UTF-8 acceptance, checked/unchecked conversions, and serde bytes semantics. |
tests/search.rs |
Adds search semantics tests (empty needle, byte indices, unicode alignment, reusable finder). |
tests/mutation.rs |
Adds mutation/buffer-reuse regression tests for push_str, add, reserve. |
tests/layout_snapshot.rs |
Adds a layout snapshot test that writes JSON artifacts for CI/benchmarking. |
benches/comprehensive.rs |
Updates benches to use checked UTF-8 construction. |
benches/layout.rs |
Adds a bench target that emits layout JSON artifacts. |
benches/mutation.rs |
Adds mutation-focused criterion benchmarks. |
benches/pattern.rs |
Adds substring-search-focused criterion benchmarks and finder comparisons. |
scripts/bench-all.sh |
Adds a convenience runner for tests/benches and capturing outputs. |
scripts/bench-all.ps1 |
Windows equivalent for capturing test/bench outputs. |
bench-results/README.md |
Documents intended artifact layout for benchmark outputs. |
README.md |
Updates docs for new version, search behavior, and CheetahBytes feature semantics. |
.github/workflows/ci.yaml |
Expands CI matrix and uploads layout snapshot artifacts. |
.github/workflows/release.yml |
Adds a release workflow that validates versions, runs checks/tests, and publishes/releases. |
Comments suppressed due to low confidence (1)
src/serde.rs:78
CheetahStringVisitorimplementsvisit_bytes/visit_byte_buf, butcheetah_string()callsdeserializer.deserialize_str(...), which will never dispatch to those byte-oriented visitor methods. If the intent is to accept byte buffers (while validating UTF-8), switch todeserialize_any(ordeserialize_bytes/deserialize_byte_bufwith appropriate visitor methods); otherwise remove the unused byte visitor methods to avoid misleading behavior.
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
where
E: Error,
{
str::from_utf8(v)
.map(CheetahString::from_slice)
.map_err(Error::custom)
}
fn visit_borrowed_bytes<E>(self, v: &'a [u8]) -> Result<Self::Value, E>
where
E: Error,
{
str::from_utf8(v)
.map(CheetahString::from_slice)
.map_err(Error::custom)
}
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
where
E: Error,
{
CheetahString::try_from_vec(v).map_err(Error::custom)
}
}
deserializer.deserialize_str(CheetahStringVisitor)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #!/usr/bin/env sh | ||
| set -eu |
| cargo test layout_snapshot --all-features -- --nocapture | | ||
| Tee-Object -FilePath (Join-Path $ResultDir "layout-test.txt") | ||
|
|
| [package] | ||
| name = "cheetah-string" | ||
| version = "1.0.1" | ||
| version = "1.1.0" | ||
| authors = ["mxsm <mxsm@apache.org>"] |
Implements the CheetahBytes stage.
Scope:
CheetahBytesbehind thebytesfeature.CheetahString.CheetahBytesonly.Verification completed locally:
cargo test --features bytescargo test --features "bytes serde"cargo test --no-default-features --features "bytes serde"Closes #113.