Repository navigation
Forward nth and size_hint on JsStr windows iterator - #5663
Open
shu-chen-dot-ca wants to merge 1 commit into
Open
shu-chen-dot-ca wants to merge 1 commit into
shu-chen-dot-ca wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request fixes/closes #5651.
JsStr::index_of(StringIndexOf) doesself.windows(n).skip(from_index). OurWindowswrapper only implementednext, soSkipfell back to the defaultIterator::nth, which callsnextonce per skipped window. Every search therefore costO(from_index)before its first comparison, which made forwardindexOfloops,includeswith a position, andsplit/replaceAllwith a string pattern quadratic in the string length.It changes the following:
Windowsnow forwardsnthandsize_hintto the innerstd::slice::Windows, so skipping is constant time (andsize_hintis exact, matching the existingExactSizeIteratorimpl).windows_nth_and_size_hint(checksnth,size_hintand the followingnextagainststd::slice::Windowsfor Latin-1 and UTF-16, every window size and skip count, including out of range ones).index_of_from_index(comparesindex_ofagainst a naive search for everyfrom_indexup tolen + 2, for one- and two-unit needles and the empty needle, on Latin-1 and UTF-16 strings, plus a match right at a largefrom_index).Timings with the release
boaCLI on a string of"abcdefghi@".repeat(40000)(400,000 units, 40,000 matches):indexOfloop from the previous matchsplit("@")replaceAll("@", "#")indexOfloop, UTF-16 stringlastIndexOfloop (unchanged, for comparison)All results are identical before and after.
Tested with:
cargo fmt --all --checkcargo clippy -p boa_string --all-features --all-targets -- -D warningscargo test -p boa_stringcargo test -p boa_engine -- builtins::string builtins::regexpScreenshots