Skip to content

Commit c74229f

Browse files
authored
Merge pull request #1608 from otaviolima/minor-optmization
2 parents eaafb67 + 688a00a commit c74229f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Foundation/ByteCountFormatter.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,17 @@ open class ByteCountFormatter : Formatter {
326326

327327
// A helper method to return the length of an int
328328
private func lengthOfInt(number: Int) -> Int {
329+
guard number != 0 else {
330+
return 1
331+
}
329332
var num = abs(number)
330-
var length: [Int] = []
333+
var length = 0
331334

332335
while num > 0 {
333-
let remainder = num % 10
334-
length.append(remainder)
336+
length += 1
335337
num /= 10
336338
}
337-
return length.count
339+
return length
338340
}
339341

340342
// Returns the correct string based on the includesValue and includesUnit properties

0 commit comments

Comments
 (0)