Skip to content

Commit a808209

Browse files
committed
Optimise GPXRoot
1 parent 37bcc4d commit a808209

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

Classes/GPXRoot.swift

+9-21
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,8 @@ open class GPXRoot: GPXElement {
5555
}
5656

5757
public func add(waypoint: GPXWaypoint?) {
58-
if waypoint != nil {
59-
let contains = waypoints.contains(waypoint!)
60-
if contains == false {
61-
waypoint?.parent = self
62-
waypoints.append(waypoint!)
63-
}
58+
if let validWaypoint = waypoint {
59+
self.waypoints.append(validWaypoint)
6460
}
6561
}
6662

@@ -73,7 +69,7 @@ open class GPXRoot: GPXElement {
7369
if contains == true {
7470
waypoint.parent = nil
7571
if let index = waypoints.firstIndex(of: waypoint) {
76-
waypoints.remove(at: index)
72+
self.waypoints.remove(at: index)
7773
}
7874
}
7975
}
@@ -87,12 +83,8 @@ open class GPXRoot: GPXElement {
8783
}
8884

8985
public func add(route: GPXRoute?) {
90-
if route != nil {
91-
let contains = routes.contains(route!)
92-
if contains == false {
93-
route?.parent = self
94-
routes.append(route!)
95-
}
86+
if let validRoute = route {
87+
self.routes.append(validRoute)
9688
}
9789
}
9890

@@ -105,7 +97,7 @@ open class GPXRoot: GPXElement {
10597
if contains == true {
10698
route.parent = nil
10799
if let index = routes.firstIndex(of: route) {
108-
waypoints.remove(at: index)
100+
self.waypoints.remove(at: index)
109101
}
110102
}
111103
}
@@ -117,12 +109,8 @@ open class GPXRoot: GPXElement {
117109
}
118110

119111
public func add(track: GPXTrack?) {
120-
if track != nil {
121-
let contains = tracks.contains(track!)
122-
if contains == false {
123-
track?.parent = self
124-
tracks.append(track!)
125-
}
112+
if let validTrack = track {
113+
self.tracks.append(validTrack)
126114
}
127115
}
128116

@@ -135,7 +123,7 @@ open class GPXRoot: GPXElement {
135123
if contains == true {
136124
track.parent = nil
137125
if let index = tracks.firstIndex(of: track) {
138-
waypoints.remove(at: index)
126+
self.waypoints.remove(at: index)
139127
}
140128
}
141129
}

0 commit comments

Comments
 (0)