Skip to content

Commit

Permalink
Fix infinite loops (#2531)
Browse files Browse the repository at this point in the history
* fix infinite loop happening on identical file names.

* fix whitespaces

* better style.
  • Loading branch information
lejuyan authored and lhc70000 committed Jan 13, 2020
1 parent 23026ea commit f4cb799
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion iina/FileGroup.swift
Expand Up @@ -108,7 +108,8 @@ class FileGroup {
var i = prefix.count

while tempGroup.count < 2 {
var lastPrefix = ""
var lastPrefix = prefix
var anyProcessed = false
for finfo in contents {
// if reached string end
if i >= finfo.characters.count {
Expand All @@ -125,6 +126,7 @@ class FileGroup {
currChars.append((c, p))
}
tempGroup[p]!.append(finfo)
anyProcessed = true
}
// if all items have the same prefix
if tempGroup.count == 1 {
Expand All @@ -133,6 +135,10 @@ class FileGroup {
currChars.removeAll()
}
i += 1
// if all items have the same name
if !anyProcessed {
break
}
}

let maxSubGroupCount = tempGroup.reduce(0, { max($0, $1.value.count) })
Expand Down

0 comments on commit f4cb799

Please sign in to comment.