Skip to content

Commit 5a32c12

Browse files
authored
Merge pull request #1594 from rauhul/remove_unnecessary_casts
Remove unnecessary casts within FileManager
2 parents ac8a8eb + 0a6f5a3 commit 5a32c12

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Foundation/FileManager.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ open class FileManager : NSObject {
300300

301301
try _contentsOfDir(atPath: path, { (entryName, entryType) throws in
302302
contents.append(entryName)
303-
if entryType == Int32(DT_DIR) {
303+
if entryType == DT_DIR {
304304
let subPath: String = path + "/" + entryName
305305
let entries = try subpathsOfDirectory(atPath: subPath)
306306
contents.append(contentsOf: entries.map({file in "\(entryName)/\(file)"}))
@@ -434,7 +434,7 @@ open class FileManager : NSObject {
434434
let bufSize = Int(PATH_MAX + 1)
435435
var buf = [Int8](repeating: 0, count: bufSize)
436436
let len = _fileSystemRepresentation(withPath: path) {
437-
readlink($0, &buf, bufSize)
437+
readlink($0, &buf, bufSize)
438438
}
439439
if len < 0 {
440440
throw _NSErrorWithErrno(errno, reading: true, path: path)
@@ -503,6 +503,7 @@ open class FileManager : NSObject {
503503
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(fileInfo.st_blksize))
504504
defer { buffer.deallocate() }
505505

506+
// Casted to Int64 because fileInfo.st_size is 64 bits long even on 32 bit platforms
506507
var bytesRemaining = Int64(fileInfo.st_size)
507508
while bytesRemaining > 0 {
508509
let bytesToRead = min(bytesRemaining, Int64(fileInfo.st_blksize))
@@ -696,8 +697,7 @@ open class FileManager : NSObject {
696697
let length = Int(PATH_MAX) + 1
697698
var buf = [Int8](repeating: 0, count: length)
698699
getcwd(&buf, length)
699-
let result = self.string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
700-
return result
700+
return string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
701701
}
702702

703703
@discardableResult
@@ -798,8 +798,8 @@ open class FileManager : NSObject {
798798

799799
private func _compareSymlinks(withFileSystemRepresentation file1Rep: UnsafePointer<Int8>, andFileSystemRepresentation file2Rep: UnsafePointer<Int8>, size: Int64) -> Bool {
800800
let bufSize = Int(size)
801-
let buffer1 = UnsafeMutablePointer<CChar>.allocate(capacity: Int(bufSize))
802-
let buffer2 = UnsafeMutablePointer<CChar>.allocate(capacity: Int(bufSize))
801+
let buffer1 = UnsafeMutablePointer<CChar>.allocate(capacity: bufSize)
802+
let buffer2 = UnsafeMutablePointer<CChar>.allocate(capacity: bufSize)
803803

804804
let size1 = readlink(file1Rep, buffer1, bufSize)
805805
let size2 = readlink(file2Rep, buffer2, bufSize)

0 commit comments

Comments
 (0)