Skip to content

Commit da0900c

Browse files
authored
Remove dead branches (#344)
* Indices are always numbers * Arrays are never strings * key cannot be number
1 parent b400d2b commit da0900c

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

src/filters/arrays.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,18 @@ function matchItems(array1, array2, index1, index2, context) {
5050
// no way to match objects was provided, try match by position
5151
return context.matchByPosition && index1 === index2;
5252
}
53-
let hash1;
54-
let hash2;
55-
if (typeof index1 === 'number') {
56-
context.hashCache1 = context.hashCache1 || [];
57-
hash1 = context.hashCache1[index1];
58-
if (typeof hash1 === 'undefined') {
59-
context.hashCache1[index1] = hash1 = objectHash(value1, index1);
60-
}
61-
} else {
62-
hash1 = objectHash(value1);
53+
context.hashCache1 = context.hashCache1 || [];
54+
let hash1 = context.hashCache1[index1];
55+
if (typeof hash1 === 'undefined') {
56+
context.hashCache1[index1] = hash1 = objectHash(value1, index1);
6357
}
6458
if (typeof hash1 === 'undefined') {
6559
return false;
6660
}
67-
if (typeof index2 === 'number') {
68-
context.hashCache2 = context.hashCache2 || [];
69-
hash2 = context.hashCache2[index2];
70-
if (typeof hash2 === 'undefined') {
71-
context.hashCache2[index2] = hash2 = objectHash(value2, index2);
72-
}
73-
} else {
74-
hash2 = objectHash(value2);
61+
context.hashCache2 = context.hashCache2 || [];
62+
let hash2 = context.hashCache2[index2];
63+
if (typeof hash2 === 'undefined') {
64+
context.hashCache2[index2] = hash2 = objectHash(value2, index2);
7565
}
7666
if (typeof hash2 === 'undefined') {
7767
return false;

src/filters/lcs.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ const get = function (array1, array2, match, context) {
8181
match || defaultMatch,
8282
innerContext,
8383
);
84-
const result = backtrack(matrix, array1, array2, innerContext);
85-
if (typeof array1 === 'string' && typeof array2 === 'string') {
86-
result.sequence = result.sequence.join('');
87-
}
88-
return result;
84+
return backtrack(matrix, array1, array2, innerContext);
8985
};
9086

9187
export default {

src/formatters/base.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,7 @@ class BaseFormatter {
182182
if (arrayKeys && key === '_t') {
183183
continue;
184184
}
185-
const leftKey = arrayKeys
186-
? typeof key === 'number'
187-
? key
188-
: parseInt(trimUnderscore(key), 10)
189-
: key;
185+
const leftKey = arrayKeys ? parseInt(trimUnderscore(key), 10) : key;
190186
const isLast = index === length - 1;
191187
fn(key, leftKey, moveDestinations[leftKey], isLast);
192188
}

0 commit comments

Comments
 (0)