Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add memmem implementation, upgrade to Rust 2018, bump MSRV to Rust 1.41.1 #82

Merged
merged 4 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
CARGO: cargo
# When CARGO is set to CROSS, TARGET is set to `--target matrix.target`.
TARGET:
# Make quickcheck run more tests for hopefully better coverage.
QUICKCHECK_TESTS: 100000
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -31,7 +33,7 @@ jobs:
include:
- build: pinned
os: ubuntu-18.04
rust: 1.28.0
rust: 1.41.1
- build: stable
os: ubuntu-18.04
rust: stable
Expand Down
15 changes: 13 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ repository = "https://github.com/BurntSushi/rust-memchr"
readme = "README.md"
keywords = ["memchr", "char", "scan", "strchr", "string"]
license = "Unlicense/MIT"
exclude = ["/ci/*", "/.travis.yml", "/Makefile", "/appveyor.yml"]
exclude = ["/bench", "/.github", "/fuzz"]
edition = "2018"

[workspace]
members = ["bench"]

[lib]
name = "memchr"
Expand All @@ -31,7 +35,14 @@ use_std = ["std"]
libc = { version = "0.2.18", default-features = false, optional = true }

[dev-dependencies]
quickcheck = { version = "0.9", default-features = false }
quickcheck = { version = "1.0.3", default-features = false }

[profile.release]
debug = true

[profile.bench]
debug = true

[profile.test]
opt-level = 3
debug = true
62 changes: 35 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
memchr
======
The `memchr` crate provides heavily optimized routines for searching bytes.
This library provides heavily optimized routines for string search primitives.

[![Build status](https://github.com/BurntSushi/rust-memchr/workflows/ci/badge.svg)](https://github.com/BurntSushi/rust-memchr/actions)
[![](https://meritbadge.herokuapp.com/memchr)](https://crates.io/crates/memchr)
Expand All @@ -15,23 +15,15 @@ Dual-licensed under MIT or the [UNLICENSE](https://unlicense.org/).

### Overview

The `memchr` function is traditionally provided by libc, but its
performance can vary significantly depending on the specific
implementation of libc that is used. They can range from manually tuned
Assembly implementations (like that found in GNU's libc) all the way to
non-vectorized C implementations (like that found in MUSL).
* The top-level module provides routines for searching for 1, 2 or 3 bytes
in the forward or reverse direction. When searching for more than one byte,
positions are considered a match if the byte at that position matches any
of the bytes.
* The `memmem` sub-module provides forward and reverse substring search
routines.

To smooth out the differences between implementations of libc, at least
on `x86_64` for Rust 1.27+, this crate provides its own implementation of
`memchr` that should perform competitively with the one found in GNU's libc.
The implementation is in pure Rust and has no dependency on a C compiler or an
Assembler.

Additionally, GNU libc also provides an extension, `memrchr`. This crate
provides its own implementation of `memrchr` as well, on top of `memchr2`,
`memchr3`, `memrchr2` and `memrchr3`. The difference between `memchr` and
`memchr2` is that `memchr2` permits finding all occurrences of two bytes
instead of one. Similarly for `memchr3`.
In all such cases, routines operate on `&[u8]` without regard to encoding. This
is exactly what you want when searching either UTF-8 or arbitrary bytes.

### Compiling without the standard library

Expand All @@ -43,10 +35,9 @@ memchr links to the standard library by default, but you can disable the
memchr = { version = "2", default-features = false }
```

On x86 platforms, when the `std` feature is disabled, the SSE2
implementation of memchr will be used in compilers that support it. When
`std` is enabled, the AVX implementation of memchr will be used if the CPU
is determined to support it at runtime.
On x86 platforms, when the `std` feature is disabled, the SSE2 accelerated
implementations will be used. When `std` is enabled, AVX accelerated
implementations will be used if the CPU is determined to support it at runtime.

### Using libc

Expand All @@ -58,16 +49,16 @@ using `memchr` from libc is desirable and a vectorized routine is not otherwise
available in this crate, then enabling the `libc` feature will use libc's
version of `memchr`.

The rest of the functions in this crate, e.g., `memchr2` or `memrchr3`, are not
a standard part of libc, so they will always use the implementations in this
crate. One exception to this is `memrchr`, which is an extension commonly found
on Linux. On Linux, `memrchr` is used in precisely the same scenario as
`memchr`, as described above.
The rest of the functions in this crate, e.g., `memchr2` or `memrchr3` and the
substring search routines, will always use the implementations in this crate.
One exception to this is `memrchr`, which is an extension in `libc` found on
Linux. On Linux, `memrchr` is used in precisely the same scenario as `memchr`,
as described above.


### Minimum Rust version policy

This crate's minimum supported `rustc` version is `1.28.0`.
This crate's minimum supported `rustc` version is `1.41.1`.

The current policy is that the minimum Rust version required to use this crate
can be increased in minor version updates. For example, if `crate 1.0` requires
Expand All @@ -77,3 +68,20 @@ version of Rust.

In general, this crate will be conservative with respect to the minimum
supported version of Rust.


### Testing strategy

Given the complexity of the code in this crate, along with the pervasive use
of `unsafe`, this crate has an extensive testing strategy. It combines multiple
approaches:

* Hand-written tests.
* Exhaustive-style testing meant to exercise all possible branching and offset
calculations.
* Property based testing through [`quickcheck`](https://github.com/BurntSushi/quickcheck).
* Fuzz testing through [`cargo fuzz`](https://github.com/rust-fuzz/cargo-fuzz).
* A huge suite of benchmarks that are also run as tests. Benchmarks always
confirm that the expected result occurs.

Improvements to the testing infrastructue are very welcome.
Loading