Skip to content

Commit

Permalink
Use autorelease pool for regex search
Browse files Browse the repository at this point in the history
  • Loading branch information
leits committed Mar 20, 2024
1 parent 7a34049 commit da6eaf9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
42 changes: 24 additions & 18 deletions MeetingBar/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,38 @@ struct ProcessedEvent: Codable, Defaults.Serializable, Hashable {
*/
func cleanupOutlookSafeLinks(rawText: String) -> String {
var text = rawText
var links = UtilsRegex.outlookSafeLinkRegex.matches(in: text, range: NSRange(text.startIndex..., in: text))
if !links.isEmpty {
repeat {
let urlRange = links[0].range(at: 1)
let safeLinks = links.map { String(text[Range($0.range, in: text)!]) }
if !safeLinks.isEmpty {
let serviceUrl = (text as NSString).substring(with: urlRange)
if let decodedServiceURL = serviceUrl.decodeUrl() {
text = text.replacingOccurrences(of: safeLinks[0], with: decodedServiceURL)
autoreleasepool {
var links = UtilsRegex.outlookSafeLinkRegex.matches(in: text, range: NSRange(text.startIndex..., in: text))
if !links.isEmpty {
repeat {
let urlRange = links[0].range(at: 1)
let safeLinks = links.map { String(text[Range($0.range, in: text)!]) }
if !safeLinks.isEmpty {
let serviceUrl = (text as NSString).substring(with: urlRange)
if let decodedServiceURL = serviceUrl.decodeUrl() {
text = text.replacingOccurrences(of: safeLinks[0], with: decodedServiceURL)
}
}
}
links = UtilsRegex.outlookSafeLinkRegex.matches(in: text, range: NSRange(text.startIndex..., in: text))
} while !links.isEmpty
links = UtilsRegex.outlookSafeLinkRegex.matches(in: text, range: NSRange(text.startIndex..., in: text))
} while !links.isEmpty
}
}
return text
}

func getMatch(text: String, regex: NSRegularExpression) -> String? {
let resultsIterator = regex.matches(in: text, range: NSRange(text.startIndex..., in: text))
let resultsMap = resultsIterator.map { String(text[Range($0.range, in: text)!]) }
var match: String?

autoreleasepool {
let resultsIterator = regex.matches(in: text, range: NSRange(text.startIndex..., in: text))
let resultsMap = resultsIterator.map { String(text[Range($0.range, in: text)!]) }

if !resultsMap.isEmpty {
let match = resultsMap[0]
return match
if !resultsMap.isEmpty {
match = resultsMap[0]
}
}
return nil

return match
}

func cleanUpNotes(_ notes: String) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Defaults
import SwiftUI

struct AutoJoinScreen: View {
struct FullscreenNotification: View {
var event: MBEvent
var window: NSWindow?

Expand Down Expand Up @@ -72,5 +72,5 @@ struct VisualEffect: NSViewRepresentable {
}

#Preview {
AutoJoinScreen(event: generateFakeEvent(), window: nil)
FullscreenNotification(event: generateFakeEvent(), window: nil)
}

0 comments on commit da6eaf9

Please sign in to comment.