Skip to content

Commit ed39232

Browse files
committed
Improve control flow
1 parent e2a1d0c commit ed39232

File tree

1 file changed

+38
-50
lines changed

1 file changed

+38
-50
lines changed

Foundation/NSXMLParser.swift

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -73,48 +73,40 @@ internal func _NSXMLParserExternalEntityWithURL(interface: _CFXMLInterface, urlS
7373

7474
switch policy {
7575
case .ResolveExternalEntitiesSameOriginOnly:
76-
if let url = parser._url {
77-
if a == nil {
78-
a = NSURL(string: String(urlStr))
76+
guard let url = parser._url else { break }
77+
78+
if a == nil {
79+
a = NSURL(string: String(urlStr))
80+
}
81+
82+
guard let aUrl = a else { break }
83+
84+
var matches: Bool
85+
if let aHost = aUrl.host, host = url.host {
86+
matches = host == aHost
87+
} else {
88+
return nil
89+
}
90+
91+
if matches {
92+
if let aPort = aUrl.port, port = url.port {
93+
matches = port == aPort
94+
} else {
95+
return nil
7996
}
80-
if let aUrl = a {
81-
var matches: Bool
82-
if let aHost = aUrl.host {
83-
if let host = url.host {
84-
matches = host == aHost
85-
} else {
86-
matches = false
87-
}
88-
} else {
89-
matches = false
90-
}
91-
if matches {
92-
if let aPort = aUrl.port {
93-
if let port = url.port {
94-
matches = port == aPort
95-
} else {
96-
matches = false
97-
}
98-
} else {
99-
matches = false
100-
}
101-
}
102-
if matches {
103-
if let aScheme = aUrl.scheme {
104-
if let scheme = url.scheme {
105-
matches = scheme == aScheme
106-
} else {
107-
matches = false
108-
}
109-
} else {
110-
matches = false
111-
}
112-
}
113-
if !matches {
114-
return nil
115-
}
97+
}
98+
99+
if matches {
100+
if let aScheme = aUrl.scheme, scheme = url.scheme {
101+
matches = scheme == aScheme
102+
} else {
103+
return nil
116104
}
117105
}
106+
107+
if !matches {
108+
return nil
109+
}
118110
break
119111
case .ResolveExternalEntitiesAlways:
120112
break
@@ -262,18 +254,14 @@ internal func _NSXMLParserStartElementNs(ctx: _CFXMLInterface, localname: Unsafe
262254
asAttrNamespaceNameString = "xmlns"
263255
}
264256
let namespaceValueString = namespaces[idx + 1] == nil ? UTF8STRING(namespaces[idx + 1]) : ""
265-
if (reportNamespaces) {
266-
if let k = namespaceNameString {
267-
if let v = namespaceValueString {
268-
nsDict[k] = v
269-
}
257+
if reportNamespaces {
258+
if let k = namespaceNameString, v = namespaceValueString {
259+
nsDict[k] = v
270260
}
271261
}
272262
if !reportQNameURI {
273-
if let k = asAttrNamespaceNameString {
274-
if let v = namespaceValueString {
275-
attrDict[k] = v
276-
}
263+
if let k = asAttrNamespaceNameString, v = namespaceValueString {
264+
attrDict[k] = v
277265
}
278266
}
279267
}
@@ -329,13 +317,13 @@ internal func _NSXMLParserEndElementNs(ctx: _CFXMLInterface , localname: UnsafeP
329317
let reportQNameURI = parser.shouldProcessNamespaces
330318
let prefixLen = prefix == nil ? strlen(UnsafePointer<Int8>(prefix)) : 0
331319
let localnameString = (prefixLen == 0 || reportQNameURI) ? UTF8STRING(localname) : nil
332-
let nilStr: String? = nil
320+
let nilStr: String?
333321
let qualifiedNameString = (prefixLen != 0) ? _colonSeparatedStringFromPrefixAndSuffix(prefix, prefixLen, localname, strlen(UnsafePointer<Int8>(localname))) : nilStr
334322
let namespaceURIString = reportQNameURI ? UTF8STRING(URI) : nilStr
335323

336324

337325
if let delegate = parser.delegate {
338-
if (reportQNameURI) {
326+
if reportQNameURI {
339327
// When reporting namespace info, the delegate parameters are not passed in nil
340328
delegate.parser(parser, didEndElement: localnameString!, namespaceURI: namespaceURIString == nil ? "" : namespaceURIString, qualifiedName: qualifiedNameString == nil ? "" : qualifiedNameString)
341329
} else {

0 commit comments

Comments
 (0)