Garrett Johnson 5 năm trước cách đây
mục cha
commit
d903e08ccb
1 tập tin đã thay đổi với 5 bổ sung1 xóa
  1. 5 1
      src/utilities/LRUCache.js

+ 5 - 1
src/utilities/LRUCache.js

@@ -122,21 +122,25 @@ class LRUCache {
 
 			if ( prioritySortCb ) {
 
+				// used items should be at the end of the array
 				itemList.sort( ( a, b ) => {
 
 					const usedA = usedSet.has( a );
 					const usedB = usedSet.has( b );
 					if ( usedA && usedB ) {
 
+						// If they're both used then don't bother moving them
 						return 0;
 
 					} else if ( ! usedA && ! usedB ) {
 
+						// Use the sort function otherwise
 						return prioritySortCb( a, b );
 
 					} else {
 
-						return usedA ? - 1 : 1;
+						// If one is used and the other is not move the used one towards the end of the array
+						return usedA ? 1 : - 1;
 
 					}