Skip to content

Commit 4de422e

Browse files
committed
tweaks
1 parent 4629565 commit 4de422e

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

SwiftIO/SocketEngine.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension String {
3030
}
3131
}
3232

33-
private typealias Probe = (msg:String, type:PacketType, data:[NSData]?)
33+
private typealias Probe = (msg:String, type:PacketType, data:ContiguousArray<NSData>?)
3434
private typealias ProbeWaitQueue = [Probe]
3535

3636
public enum PacketType: String {
@@ -477,7 +477,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
477477
}
478478

479479
/// Send an engine message (4)
480-
public func send(msg:String, withData datas:[NSData]?) {
480+
public func send(msg:String, withData datas:ContiguousArray<NSData>?) {
481481
if self.probing {
482482
self.probeWait.append((msg, PacketType.MESSAGE, datas))
483483
} else {
@@ -494,9 +494,8 @@ public class SocketEngine: NSObject, WebSocketDelegate {
494494
}
495495

496496
private func sendPollMessage(var msg:String, withType type:PacketType,
497-
datas:[NSData]? = nil) {
497+
datas:ContiguousArray<NSData>? = nil) {
498498
// println("Sending poll: \(msg) as type: \(type.rawValue)")
499-
500499
doubleEncodeUTF8(&msg)
501500
let strMsg = "\(type.rawValue)\(msg)"
502501

@@ -515,18 +514,19 @@ public class SocketEngine: NSObject, WebSocketDelegate {
515514
}
516515
}
517516

518-
private func sendWebSocketMessage(str:String, withType type:PacketType, datas:[NSData]? = nil) {
519-
// println("Sending ws: \(str) as type: \(type.rawValue)")
520-
self.ws?.writeString("\(type.rawValue)\(str)")
521-
522-
if datas != nil {
523-
for data in datas! {
524-
let (data, nilString) = self.createBinaryDataForSend(data)
525-
if data != nil {
526-
self.ws?.writeData(data!)
517+
private func sendWebSocketMessage(str:String, withType type:PacketType,
518+
datas:ContiguousArray<NSData>? = nil) {
519+
// println("Sending ws: \(str) as type: \(type.rawValue)")
520+
self.ws?.writeString("\(type.rawValue)\(str)")
521+
522+
if datas != nil {
523+
for data in datas! {
524+
let (data, nilString) = self.createBinaryDataForSend(data)
525+
if data != nil {
526+
self.ws?.writeData(data!)
527+
}
527528
}
528529
}
529-
}
530530
}
531531

532532
// Starts the ping timer
@@ -552,7 +552,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
552552
}
553553
}
554554

555-
public func write(msg:String, withType type:PacketType, withData data:[NSData]?) {
555+
public func write(msg:String, withType type:PacketType, withData data:ContiguousArray<NSData>?) {
556556
dispatch_async(self.emitQueue) {[weak self] in
557557
if self == nil {
558558
return

SwiftIO/SocketPacket.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum SocketPacketType: Int {
4343
}
4444

4545
class SocketPacket {
46-
var binary = [NSData]()
46+
var binary = ContiguousArray<NSData>()
4747
var currentPlace = 0
4848
var data:[AnyObject]?
4949
var id:Int?

SwiftIO/SocketParser.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,16 @@ private let shredder = SocketParser.Deconstructor()
2727
class SocketParser {
2828
// Translation of socket.io-parser#deconstructPacket
2929
private class Deconstructor {
30-
var buf = [NSData]()
31-
30+
var buf = ContiguousArray<NSData>()
31+
3232
func ripAndTear(data:AnyObject) -> AnyObject {
3333
if let bin = data as? NSData {
3434
let placeholder = ["_placeholder" :true, "num": buf.count]
3535

3636
buf.append(bin)
3737

3838
return placeholder
39-
}
40-
41-
if var arr = data as? [AnyObject] {
39+
} else if var arr = data as? [AnyObject] {
4240
for i in 0..<arr.count {
4341
arr[i] = ripAndTear(arr[i])
4442
}

0 commit comments

Comments
 (0)