Skip to content

Commit ba1dc47

Browse files
Copilotbgoncal
andcommitted
Optimize path extraction by storing prefix in variable
Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
1 parent 5058c49 commit ba1dc47

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sources/Shared/Common/SiriIntents+ConvenienceInits.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,16 @@ public extension IntentPanel {
156156
let server = Current.servers.server(for: self) ?? Current.servers.all.first
157157
// Extract the path from the identifier (format: "serverIdentifier-path")
158158
let path: String
159-
if let identifier, let serverIdentifier, identifier.hasPrefix("\(serverIdentifier)-") {
160-
// Remove the server identifier prefix and the separator to get the path
161-
path = String(identifier.dropFirst(serverIdentifier.count + 1))
159+
if let identifier, let serverIdentifier {
160+
let prefix = serverIdentifier + "-"
161+
if identifier.hasPrefix(prefix) {
162+
// Remove the server identifier prefix and the separator to get the path
163+
path = String(identifier.dropFirst(prefix.count))
164+
} else {
165+
// Fallback for old identifiers or if extraction fails
166+
path = identifier
167+
}
162168
} else {
163-
// Fallback for old identifiers or if extraction fails
164169
path = identifier ?? "lovelace"
165170
}
166171
return AppConstants.openPageDeeplinkURL(

0 commit comments

Comments
 (0)