Skip to content
Permalink
Browse files
Remove unneeded underscores from variable names
  • Loading branch information
freak4pc committed Oct 6, 2020
1 parent bab9502 commit f92f8b72407c57c261362fe57d3ee77b19899da1
Show file tree
Hide file tree
Showing 138 changed files with 2,501 additions and 2,505 deletions.
@@ -10,14 +10,14 @@
struct InfiniteSequence<Element> : Sequence {
typealias Iterator = AnyIterator<Element>

private let _repeatedValue: Element
private let repeatedValue: Element

init(repeatedValue: Element) {
_repeatedValue = repeatedValue
self.repeatedValue = repeatedValue
}

func makeIterator() -> Iterator {
let repeatedValue = _repeatedValue
let repeatedValue = self.repeatedValue
return AnyIterator { repeatedValue }
}
}
@@ -7,27 +7,27 @@
//
struct PriorityQueue<Element> {
private let _hasHigherPriority: (Element, Element) -> Bool
private let _isEqual: (Element, Element) -> Bool
private let hasHigherPriority: (Element, Element) -> Bool
private let isEqual: (Element, Element) -> Bool

private var _elements = [Element]()
private var elements = [Element]()

init(hasHigherPriority: @escaping (Element, Element) -> Bool, isEqual: @escaping (Element, Element) -> Bool) {
_hasHigherPriority = hasHigherPriority
_isEqual = isEqual
self.hasHigherPriority = hasHigherPriority
self.isEqual = isEqual
}

mutating func enqueue(_ element: Element) {
_elements.append(element)
bubbleToHigherPriority(_elements.count - 1)
elements.append(element)
bubbleToHigherPriority(elements.count - 1)
}

func peek() -> Element? {
_elements.first
elements.first
}

var isEmpty: Bool {
_elements.count == 0
elements.count == 0
}

mutating func dequeue() -> Element? {
@@ -41,21 +41,21 @@ struct PriorityQueue<Element> {
}

mutating func remove(_ element: Element) {
for i in 0 ..< _elements.count {
if _isEqual(_elements[i], element) {
for i in 0 ..< elements.count {
if self.isEqual(elements[i], element) {
removeAt(i)
return
}
}
}

private mutating func removeAt(_ index: Int) {
let removingLast = index == _elements.count - 1
let removingLast = index == elements.count - 1
if !removingLast {
_elements.swapAt(index, _elements.count - 1)
elements.swapAt(index, elements.count - 1)
}

_ = _elements.popLast()
_ = elements.popLast()

if !removingLast {
bubbleToHigherPriority(index)
@@ -65,21 +65,21 @@ struct PriorityQueue<Element> {

private mutating func bubbleToHigherPriority(_ initialUnbalancedIndex: Int) {
precondition(initialUnbalancedIndex >= 0)
precondition(initialUnbalancedIndex < _elements.count)
precondition(initialUnbalancedIndex < elements.count)

var unbalancedIndex = initialUnbalancedIndex

while unbalancedIndex > 0 {
let parentIndex = (unbalancedIndex - 1) / 2
guard _hasHigherPriority(_elements[unbalancedIndex], _elements[parentIndex]) else { break }
_elements.swapAt(unbalancedIndex, parentIndex)
guard self.hasHigherPriority(elements[unbalancedIndex], elements[parentIndex]) else { break }
elements.swapAt(unbalancedIndex, parentIndex)
unbalancedIndex = parentIndex
}
}

private mutating func bubbleToLowerPriority(_ initialUnbalancedIndex: Int) {
precondition(initialUnbalancedIndex >= 0)
precondition(initialUnbalancedIndex < _elements.count)
precondition(initialUnbalancedIndex < elements.count)

var unbalancedIndex = initialUnbalancedIndex
while true {
@@ -88,16 +88,16 @@ struct PriorityQueue<Element> {

var highestPriorityIndex = unbalancedIndex

if leftChildIndex < _elements.count && _hasHigherPriority(_elements[leftChildIndex], _elements[highestPriorityIndex]) {
if leftChildIndex < elements.count && self.hasHigherPriority(elements[leftChildIndex], elements[highestPriorityIndex]) {
highestPriorityIndex = leftChildIndex
}

if rightChildIndex < _elements.count && _hasHigherPriority(_elements[rightChildIndex], _elements[highestPriorityIndex]) {
if rightChildIndex < elements.count && self.hasHigherPriority(elements[rightChildIndex], elements[highestPriorityIndex]) {
highestPriorityIndex = rightChildIndex
}

guard highestPriorityIndex != unbalancedIndex else { break }
_elements.swapAt(highestPriorityIndex, unbalancedIndex)
elements.swapAt(highestPriorityIndex, unbalancedIndex)

unbalancedIndex = highestPriorityIndex
}
@@ -106,6 +106,6 @@ struct PriorityQueue<Element> {

extension PriorityQueue : CustomDebugStringConvertible {
var debugDescription: String {
_elements.debugDescription
elements.debugDescription
}
}
@@ -18,77 +18,77 @@ struct Queue<T>: Sequence {
/// Type of generator.
typealias Generator = AnyIterator<T>

private let _resizeFactor = 2
private let resizeFactor = 2

private var _storage: ContiguousArray<T?>
private var _count = 0
private var _pushNextIndex = 0
private let _initialCapacity: Int
private var storage: ContiguousArray<T?>
private var innerCount = 0
private var pushNextIndex = 0
private let initialCapacity: Int

/**
Creates new queue.
- parameter capacity: Capacity of newly created queue.
*/
init(capacity: Int) {
_initialCapacity = capacity
initialCapacity = capacity

_storage = ContiguousArray<T?>(repeating: nil, count: capacity)
storage = ContiguousArray<T?>(repeating: nil, count: capacity)
}

private var dequeueIndex: Int {
let index = _pushNextIndex - count
return index < 0 ? index + _storage.count : index
let index = pushNextIndex - count
return index < 0 ? index + storage.count : index
}

/// - returns: Is queue empty.
var isEmpty: Bool { count == 0 }

/// - returns: Number of elements inside queue.
var count: Int { _count }
var count: Int { innerCount }

/// - returns: Element in front of a list of elements to `dequeue`.
func peek() -> T {
precondition(count > 0)

return _storage[dequeueIndex]!
return storage[dequeueIndex]!
}

mutating private func resizeTo(_ size: Int) {
var newStorage = ContiguousArray<T?>(repeating: nil, count: size)

let count = _count
let count = self.count

let dequeueIndex = self.dequeueIndex
let spaceToEndOfQueue = _storage.count - dequeueIndex
let spaceToEndOfQueue = storage.count - dequeueIndex

// first batch is from dequeue index to end of array
let countElementsInFirstBatch = Swift.min(count, spaceToEndOfQueue)
// second batch is wrapped from start of array to end of queue
let numberOfElementsInSecondBatch = count - countElementsInFirstBatch

newStorage[0 ..< countElementsInFirstBatch] = _storage[dequeueIndex ..< (dequeueIndex + countElementsInFirstBatch)]
newStorage[countElementsInFirstBatch ..< (countElementsInFirstBatch + numberOfElementsInSecondBatch)] = _storage[0 ..< numberOfElementsInSecondBatch]
newStorage[0 ..< countElementsInFirstBatch] = storage[dequeueIndex ..< (dequeueIndex + countElementsInFirstBatch)]
newStorage[countElementsInFirstBatch ..< (countElementsInFirstBatch + numberOfElementsInSecondBatch)] = storage[0 ..< numberOfElementsInSecondBatch]

_count = count
_pushNextIndex = count
_storage = newStorage
self.innerCount = count
pushNextIndex = count
storage = newStorage
}

/// Enqueues `element`.
///
/// - parameter element: Element to enqueue.
mutating func enqueue(_ element: T) {
if count == _storage.count {
resizeTo(Swift.max(_storage.count, 1) * _resizeFactor)
if count == storage.count {
resizeTo(Swift.max(storage.count, 1) * resizeFactor)
}

_storage[_pushNextIndex] = element
_pushNextIndex += 1
_count += 1
storage[pushNextIndex] = element
pushNextIndex += 1
innerCount += 1

if _pushNextIndex >= _storage.count {
_pushNextIndex -= _storage.count
if pushNextIndex >= storage.count {
pushNextIndex -= storage.count
}
}

@@ -98,11 +98,11 @@ struct Queue<T>: Sequence {
let index = dequeueIndex

defer {
_storage[index] = nil
_count -= 1
storage[index] = nil
innerCount -= 1
}

return _storage[index]!
return storage[index]!
}

/// Dequeues element or throws an exception in case queue is empty.
@@ -114,9 +114,9 @@ struct Queue<T>: Sequence {
}

defer {
let downsizeLimit = _storage.count / (_resizeFactor * _resizeFactor)
if _count < downsizeLimit && downsizeLimit >= _initialCapacity {
resizeTo(_storage.count / _resizeFactor)
let downsizeLimit = storage.count / (resizeFactor * resizeFactor)
if count < downsizeLimit && downsizeLimit >= initialCapacity {
resizeTo(storage.count / resizeFactor)
}
}

@@ -126,23 +126,23 @@ struct Queue<T>: Sequence {
/// - returns: Generator of contained elements.
func makeIterator() -> AnyIterator<T> {
var i = dequeueIndex
var count = _count
var innerCount = count

return AnyIterator {
if count == 0 {
if innerCount == 0 {
return nil
}

defer {
count -= 1
innerCount -= 1
i += 1
}

if i >= self._storage.count {
i -= self._storage.count
if i >= self.storage.count {
i -= self.storage.count
}

return self._storage[i]
return self.storage[i]
}
}
}
@@ -25,19 +25,19 @@ import RxSwift
#endif

final class RunLoopLock {
let _currentRunLoop: CFRunLoop
let currentRunLoop: CFRunLoop

let _calledRun = AtomicInt(0)
let _calledStop = AtomicInt(0)
var _timeout: TimeInterval?
let calledRun = AtomicInt(0)
let calledStop = AtomicInt(0)
var timeout: TimeInterval?

init(timeout: TimeInterval?) {
self._timeout = timeout
self._currentRunLoop = CFRunLoopGetCurrent()
self.timeout = timeout
self.currentRunLoop = CFRunLoopGetCurrent()
}

func dispatch(_ action: @escaping () -> Void) {
CFRunLoopPerformBlock(self._currentRunLoop, runLoopModeRaw) {
CFRunLoopPerformBlock(self.currentRunLoop, runLoopModeRaw) {
if CurrentThreadScheduler.isScheduleRequired {
_ = CurrentThreadScheduler.instance.schedule(()) { _ in
action()
@@ -48,24 +48,24 @@ final class RunLoopLock {
action()
}
}
CFRunLoopWakeUp(self._currentRunLoop)
CFRunLoopWakeUp(self.currentRunLoop)
}

func stop() {
if decrement(self._calledStop) > 1 {
if decrement(self.calledStop) > 1 {
return
}
CFRunLoopPerformBlock(self._currentRunLoop, runLoopModeRaw) {
CFRunLoopStop(self._currentRunLoop)
CFRunLoopPerformBlock(self.currentRunLoop, runLoopModeRaw) {
CFRunLoopStop(self.currentRunLoop)
}
CFRunLoopWakeUp(self._currentRunLoop)
CFRunLoopWakeUp(self.currentRunLoop)
}

func run() throws {
if increment(self._calledRun) != 0 {
if increment(self.calledRun) != 0 {
fatalError("Run can be only called once")
}
if let timeout = self._timeout {
if let timeout = self.timeout {
#if os(Linux)
switch Int(CFRunLoopRunInMode(runLoopModeRaw, timeout, false)) {
case kCFRunLoopRunFinished:
@@ -134,13 +134,13 @@ extension Reactive where Base: AnyObject {
public var deallocated: Observable<Void> {
return self.synchronized {
if let deallocObservable = objc_getAssociatedObject(self.base, &deallocatedSubjectContext) as? DeallocObservable {
return deallocObservable._subject
return deallocObservable.subject
}

let deallocObservable = DeallocObservable()

objc_setAssociatedObject(self.base, &deallocatedSubjectContext, deallocObservable, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
return deallocObservable._subject
return deallocObservable.subject
}
}

@@ -336,14 +336,14 @@ extension Reactive where Base: AnyObject {


private final class DeallocObservable {
let _subject = ReplaySubject<Void>.create(bufferSize:1)
let subject = ReplaySubject<Void>.create(bufferSize:1)

init() {
}

deinit {
self._subject.on(.next(()))
self._subject.on(.completed)
self.subject.on(.next(()))
self.subject.on(.completed)
}
}

0 comments on commit f92f8b7

Please sign in to comment.