-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Replace let/nil-check patterns with guard let
#157
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
Changes from 1 commit
8df71f8
4b4c4dc
e02ca76
98230e6
2451d06
40584f8
76eb96e
ffc60a2
ecc94f2
65b69ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -584,19 +584,17 @@ extension SequenceType | |
| // A fast implementation for when you are backed by a contiguous array. | ||
| public func _initializeTo(ptr: UnsafeMutablePointer<Generator.Element>) | ||
| -> UnsafeMutablePointer<Generator.Element> { | ||
| let s = self._baseAddressIfContiguous | ||
| if s != nil { | ||
| let count = self.count | ||
| ptr.initializeFrom(s, count: count) | ||
| _fixLifetime(self._owner) | ||
| return ptr + count | ||
| } else { | ||
| guard let s = self._baseAddressIfContiguous else { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't feel this is an improvement either, because of the non-trivial amount of code in the |
||
| var p = ptr | ||
| for x in self { | ||
| p++.initialize(x) | ||
| } | ||
| return p | ||
| } | ||
| let count = self.count | ||
| ptr.initializeFrom(s, count: count) | ||
| _fixLifetime(self._owner) | ||
| return ptr + count | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,11 +26,10 @@ public struct LazyMapGenerator< | |
| /// since the copy was made, and no preceding call to `self.next()` | ||
| /// has returned `nil`. | ||
| public mutating func next() -> Element? { | ||
| let x = _base.next() | ||
| if x != nil { | ||
| return _transform(x!) | ||
| guard let x = _base.next() else { | ||
| return nil | ||
| } | ||
| return nil | ||
| return _transform(x) | ||
|
||
| } | ||
|
||
|
|
||
| public var base: Base { return _base } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,12 +247,11 @@ public // @testable | |
| func _stdlib_atomicLoadARCRef( | ||
| object target: UnsafeMutablePointer<AnyObject?> | ||
| ) -> AnyObject? { | ||
| let result = _swift_stdlib_atomicLoadPtrImpl( | ||
| object: UnsafeMutablePointer(target)) | ||
| if result != nil { | ||
| return Unmanaged<AnyObject>.fromOpaque(result).takeUnretainedValue() | ||
| guard let result = _swift_stdlib_atomicLoadPtrImpl( | ||
| object: UnsafeMutablePointer(target)) { | ||
| return nil | ||
| } | ||
| return nil | ||
| return Unmanaged<AnyObject>.fromOpaque(result).takeUnretainedValue() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part LGTM. |
||
| } | ||
|
|
||
| % for operation in [ 'Add', 'And', 'Or', 'Xor' ]: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer this the old way.
guardis supposed to be a quick-exit path, and in this case,ifplays that role well.