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

Short-circuit replace for Strings when pattern is not found #36961

Merged
merged 1 commit into from
Aug 11, 2020

Conversation

sostock
Copy link
Contributor

@sostock sostock commented Aug 7, 2020

This simply returns the original string if the pattern is not found (instead of allocating a new IOBuffer). This is considerably faster if the pattern is not found.

Before:

julia> @btime replace("abc", "e" => "f")
  173.027 ns (6 allocations: 288 bytes)
"abc"

After:

julia> @btime replace("abc", "e" => "f")
  37.549 ns (0 allocations: 0 bytes)
"abc"

@StefanKarpinski StefanKarpinski merged commit 447cd05 into JuliaLang:master Aug 11, 2020
simeonschaub pushed a commit to simeonschaub/julia that referenced this pull request Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants