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

Update ArrayExtensions.swift #1226

Merged
merged 2 commits into from
Dec 13, 2024
Merged

Conversation

fallwd
Copy link
Contributor

@fallwd fallwd commented Dec 5, 2024

For creating a dictionary.Dictionary(uniqueKeysWithValues:) is more efficient than reduce(into:) to. i used time profile and found a significant improvement.

Checklist

  • [ x] I checked the Contributing Guidelines before creating this request.
  • [ x] New extensions are written in Swift 5.6.
  • [ x] New extensions support iOS 12.0+ / tvOS 12.0+ / macOS 10.13+ / watchOS 4.0+, or use @available if not.
  • I have added tests for new extensions, and they passed.
  • All extensions have a clear comments explaining their functionality, all parameters and return type in English.
  • All extensions are declared as public.
  • I have added a changelog entry describing my changes.

For creating a dictionary.Dictionary(uniqueKeysWithValues:) is more efficient than reduce(into:) to. i used time profile  and found a significant improvement.
@fallwd
Copy link
Contributor Author

fallwd commented Dec 5, 2024

let items = (1...1000000).map { String($0) }

func createDictUsingUniqueKeysWithValues() {
_ = Dictionary(uniqueKeysWithValues: items.enumerated().map { ($1, $0) })
}

func createDictUsingReduce() {
_ = items.enumerated().reduce(into: [:]) { $0[$1.element] = $1.offset }
}

time profile result:
items = (1...1000000).map { String($0) }
createDictUsingReduce() 125ms
createDictUsingUniqueKeysWithValues() 63ms

items = (1...100000000).map { String($0) }
createDictUsingReduce() 20.26s
createDictUsingUniqueKeysWithValues() 12.58s

@fallwd
Copy link
Contributor Author

fallwd commented Dec 8, 2024

Darwin error:
/Users/runner/work/SwifterSwift/SwifterSwift/Sources/SwifterSwift/Foundation/NSAttributedStringExtensions.swift:112:63: error: cannot find 'pattern' in scope
guard let pattern = try? NSRegularExpression(pattern: pattern, options: options) else { return self }

@SwifterSwiftBot
Copy link

2 Warnings
⚠️ Consider adding tests for new extensions or updating existing tests for a modified SwifterSwift extension
⚠️ The source files have been modified. Please consider adding a CHANGELOG entry if necessary.
1 Message
📖 Thank you for submitting a pull request to SwifterSwift. The team will review your submission as soon as possible.

Generated by 🚫 Danger

@guykogus guykogus merged commit 19d8965 into SwifterSwift:master Dec 13, 2024
7 checks passed
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.22%. Comparing base (c4571a9) to head (3120295).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1226   +/-   ##
=======================================
  Coverage   68.22%   68.22%           
=======================================
  Files          98       98           
  Lines        3647     3647           
=======================================
  Hits         2488     2488           
  Misses       1159     1159           
Flag Coverage Δ
macos 97.07% <100.00%> (ø)
tvos 59.04% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

3 participants