We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
md5: a019946d343f3e398647d7c8f94dddec
Issue Description:
The following piece of code:
import Foundation let repeating = "\"." let original = String(repeating: repeating, count: 1000000) let start = Date() _ = original.replacingOccurrences(of: "\"", with: "") print("took: \(Date().timeIntervalSinceReferenceDate - start.timeIntervalSinceReferenceDate)")
takes over 20s on Linux (4.1 release, Ubuntu 14.04), in comparison to Darwin version, which takes 0.1s.
The cause is O(n^2) algorithm, or more precisely O(m*n), where m is number of matches, n is the length of the string, used here:
swift-corelibs-foundation/Foundation/NSString.swift
Lines 1412 to 1415 in b1647ac
If we built up a new string afresh, appending segments that don't match, we'd have O(n) algorithm.
The text was updated successfully, but these errors were encountered:
Comment by Gregor Milos (Grzegorz Miłoś) (JIRA)
PR: #1620
Sorry, something went wrong.
Rebased version of Gregor's PR: #2534
5.1 version #2536
5.0 version #2537
kevints
No branches or pull requests
Additional Detail from JIRA
md5: a019946d343f3e398647d7c8f94dddec
Issue Description:
The following piece of code:
takes over 20s on Linux (4.1 release, Ubuntu 14.04), in comparison to Darwin version, which takes 0.1s.
The cause is O(n^2) algorithm, or more precisely O(m*n), where m is number of matches, n is the length of the string, used here:
swift-corelibs-foundation/Foundation/NSString.swift
Lines 1412 to 1415 in b1647ac
If we built up a new string afresh, appending segments that don't match, we'd have O(n) algorithm.
The text was updated successfully, but these errors were encountered: