This repository was archived by the owner on May 8, 2022. It is now read-only.
File tree 1 file changed +6
-0
lines changed
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -293,6 +293,7 @@ extension Fuse {
293
293
let pattern = self . createPattern ( from: text)
294
294
295
295
var items = [ SearchResult] ( )
296
+ let itemsLock = NSLock ( )
296
297
297
298
let group = DispatchGroup ( )
298
299
let count = aList. count
@@ -303,7 +304,9 @@ extension Fuse {
303
304
self . searchQueue. async {
304
305
for (index, item) in chunk. enumerated ( ) {
305
306
if let result = self . search ( pattern, in: item) {
307
+ itemsLock. lock ( )
306
308
items. append ( ( index, result. score, result. ranges) )
309
+ itemsLock. unlock ( )
307
310
}
308
311
}
309
312
@@ -447,6 +450,7 @@ extension Fuse {
447
450
let count = aList. count
448
451
449
452
var collectionResult = [ FusableSearchResult] ( )
453
+ let resultLock = NSLock ( )
450
454
451
455
stride ( from: 0 , to: count, by: chunkSize) . forEach {
452
456
let chunk = Array ( aList [ $0..< min ( $0 + chunkSize, count) ] )
@@ -486,11 +490,13 @@ extension Fuse {
486
490
continue
487
491
}
488
492
493
+ resultLock. lock ( )
489
494
collectionResult. append ( (
490
495
index: index,
491
496
score: totalScore / Double( scores. count) ,
492
497
results: propertyResults
493
498
) )
499
+ resultLock. unlock ( )
494
500
}
495
501
496
502
group. leave ( )
You can’t perform that action at this time.
0 commit comments