about summary refs log tree commit diff
path: root/src/libcore/str/pattern.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-1598/+0
2020-06-14Group Pattern::strip_* method togetherLzu Tao-10/+10
2020-06-02Clarify the behaviour of Pattern when used with methods like str::containsAlexis Bourget-0/+37
2020-04-22Rollup merge of #71366 - faern:use-assoc-int-consts3, r=dtolnayYuki Okushi-1/+0
Use assoc int consts3 Define module level int consts with associated constants instead of `min_value()` and `max_value()`. So the code become consistent with what the docs recommend etc. Seems natural. Also remove the last usages of the int module constants from this repo (except src/test/ directory which I have still not really done anything in). Some places were missed in the previous PRs because the code uses `crate::<IntTy>` to reach the constants. This is a continuation of #70857 r? @dtolnay
2020-04-20Stop accessing module level int consts via crate::<Ty>Linus Färnstrand-1/+0
2020-04-19Update pattern docs.Eric Huss-1/+35
2020-04-13Add examples to Pattern docsIvan Tham-0/+26
2020-04-13Add period to Pattern docsIvan Tham-5/+5
2020-03-30Optimize strip_prefix and strip_suffix with str patternsNikhil Benesch-0/+85
Constructing a Searcher in strip_prefix and strip_suffix is unnecessarily slow when the pattern is a fixed-length string. Add strip_prefix and strip_suffix methods to the Pattern trait, and add optimized implementations of these methods in the str implementation. The old implementation is retained as the default for these methods.
2020-03-07Use ?-operator in more places (clippy::question_mark, had some false ↵Matthias Krüger-8/+5
negatives fixed recently)
2020-02-26don't take redundant references to operandsMatthias Krüger-1/+1
2020-01-16Document unsafe blocks in core::{cell, str, sync}Phoebe Bell-2/+11
2020-01-08Use matches macro in libcore and libstdIgor Aleksanov-8/+2
2019-12-22Format the worldMark Rousskov-101/+130
2019-12-16Rollup merge of #67249 - ranma42:improve-starts-with-literal-char, r=BurntSushiMazdak Farrokhzad-15/+4
Improve code generated for `starts_with(<literal char>)` This PR includes two minor improvements to the code generated when checking for string prefix/suffix. The first commit simplifies the str/str operation, by taking advantage of the raw UTF-8 representation. The second commit replaces the current str/char matching logic with a char->str encoding and then the previous method. The resulting code should be equivalent in the generic case (one char is being encoded versus one char being decoded), but it becomes easy to optimize in the case of a literal char, which in most cases a developer might expect to be at least as simple as that of a literal string. This PR should fix #41993
2019-12-12Minor cleanup in `Pattern::{is_prefix_of,is_suffix_of}` for `char`Andrea Canciani-4/+2
2019-12-12Prefer encoding the char when checking for string prefix/suffixAndrea Canciani-10/+4
This enables constant folding when matching a literal char. Fixes #41993.
2019-12-11Improve `str` prefix/suffix comparisonAndrea Canciani-5/+2
The comparison can be performed on the raw bytes, as the chars can only match if their UTF8 encoding matches. This avoids the `is_char_boundary` checks and translates to a straight `u8` slice comparison which is optimized to a memcmp or inline comparison where appropriate.
2019-12-11Some small readability improvementsAndre Bogus-6/+1
2019-11-06Have tidy ensure that we document all `unsafe` blocks in libcoreOliver Scherer-0/+2
2019-04-19libcore: deny more...Mazdak Farrokhzad-1/+1
2019-04-18libcore => 2018Taiki Endo-4/+4
2019-02-10libs: doc commentsAlexander Regueiro-4/+4
2019-02-10rustc: doc commentsAlexander Regueiro-2/+2
2019-01-09Misc cleanupsShotaro Yamada-2/+1
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-2/+2
2018-09-29Use impl_header_lifetime_elision in libcoreScott McMurray-2/+2
2018-06-26Deprecation of str::slice_uncheked(_mut)newpavlov-1/+1
2018-04-16Remove unwanted auto-linking and updateGuillaume Gomez-1/+1
2018-02-15spelling fix in commentSteve Klabnik-1/+1
2018-01-06Make double ended string searchers use dependent fingers (fixes #47175)Manish Goregaokar-6/+10
2018-01-01handle overflow/underflow in index offsetsManish Goregaokar-10/+15
2017-12-18Add memchr search support for multibyte charactersManish Goregaokar-48/+102
2017-12-16Fill in reverse searcher impl for charManish Goregaokar-6/+50
2017-12-13Fill in forward searcher impl for charManish Goregaokar-13/+65
2017-12-13Move CharSearcher to its own section in the fileManish Goregaokar-83/+84
2017-12-13Split out char searcher from MultiCharSearcherManish Goregaokar-29/+58
2017-12-13Remove the unused ascii_only field in CharEqSearcherManish Goregaokar-16/+0
2017-08-15use field init shorthand EVERYWHEREZack M. Davis-11/+11
Like #43008 (f668999), but _much more aggressive_.
2017-07-23Fix some doc/comment typos.Bruce Mitchener-3/+3
2017-07-20std: Cut down #[inline] annotations where not necessaryAlex Crichton-3/+3
This PR cuts down on a large number of `#[inline(always)]` and `#[inline]` annotations in libcore for various core functions. The `#[inline(always)]` annotation is almost never needed and is detrimental to debug build times as it forces LLVM to perform inlining when it otherwise wouldn't need to in debug builds. Additionally `#[inline]` is an unnecessary annoation on almost all generic functions because the function will already be monomorphized into other codegen units and otherwise rarely needs the extra "help" from us to tell LLVM to inline something. Overall this PR cut the compile time of a [microbenchmark][1] by 30% from 1s to 0.7s. [1]: https://gist.github.com/alexcrichton/a7d70319a45aa60cf36a6a7bf540dd3a
2017-06-17Inline StrSearcher::haystack()Alexander Bulaev-1/+4
2017-05-19Try to optimise char patternsSimonas Kazlauskas-1/+27
2017-02-09name anonymous fn parameters in libcore traitsTrevor Spiteri-3/+3
2016-08-24Use `#[prelude_import]` in `libcore`.Jeffrey Seyfried-2/+0
2016-06-23Use `len` instead of `size_hint` where appropiateTobias Bucher-4/+4
This makes it clearer that we're not just looking for a lower bound but rather know that the iterator is an `ExactSizeIterator`.
2016-03-20libcore: add Debug implementations to most missing typesSean McArthur-3/+15
2016-03-01Changed `std::pattern::Pattern` impl on `&'a &'a str` to `&'a &'b str`Marvin Löbel-1/+1
in order to allow a bit more felixibility in how to use it.
2015-08-18Auto merge of #27474 - bluss:twoway-reverse, r=brsonbors-64/+193
StrSearcher: Implement the complete reverse case for the two way algorithm Fix quadratic behavior in StrSearcher in reverse search with periodic needles. This commit adds the missing pieces for the "short period" case in reverse search. The short case will show up when the needle is literally periodic, for example "abababab". Two way uses a "critical factorization" of the needle: x = u v. Searching matches v first, if mismatch at character k, skip k forward. Matching u, if mismatch, skip period(x) forward. To avoid O(mn) behavior after mismatch in u, memorize the already matched prefix. The short period case requires that |u| < period(x). For the reverse search we need to compute a different critical factorization x = u' v' where |v'| < period(x), because we are searching for the reversed needle. A short v' also benefits the algorithm in general. The reverse critical factorization is computed quickly by using the same maximal suffix algorithm, but terminating as soon as we have a location with local period equal to period(x). This adds extra fields crit_pos_back and memory_back for the reverse case. The new overhead for TwoWaySearcher::new is low, and additionally I think the "short period" case is uncommon in many applications of string search. The maximal_suffix methods were updated in documentation and the algorithms updated to not use !0 and wrapping add, variable left is now 1 larger, offset 1 smaller. Use periodicity when computing byteset: in the periodic case, just iterate over one period instead of the whole needle. Example before (rfind) after (twoway_rfind) benchmark shows the removal of quadratic behavior. needle: "ab" * 100, haystack: ("bb" + "ab" * 100) * 100 ``` test periodic::rfind ... bench: 1,926,595 ns/iter (+/- 11,390) = 10 MB/s test periodic::twoway_rfind ... bench: 51,740 ns/iter (+/- 66) = 386 MB/s ```