optimize: builtins.intersectAttrs
This commit is contained in:
@@ -72,9 +72,21 @@ export const intersectAttrs =
|
|||||||
const f1 = forceAttrs(e1);
|
const f1 = forceAttrs(e1);
|
||||||
const f2 = forceAttrs(e2);
|
const f2 = forceAttrs(e2);
|
||||||
const attrs: NixAttrs = {};
|
const attrs: NixAttrs = {};
|
||||||
for (const key of Object.keys(f2)) {
|
const k1 = Object.keys(f1);
|
||||||
if (Object.hasOwn(f1, key)) {
|
const k2 = Object.keys(f2);
|
||||||
attrs[key] = f2[key];
|
if (k1.length < k2.length) {
|
||||||
|
for (let i = 0; i < k1.length; i++) {
|
||||||
|
const key = k1[i];
|
||||||
|
if (key in f2) {
|
||||||
|
attrs[key] = f2[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < k2.length; i++) {
|
||||||
|
const key = k2[i];
|
||||||
|
if (key in f1) {
|
||||||
|
attrs[key] = f2[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return attrs;
|
return attrs;
|
||||||
|
|||||||
Reference in New Issue
Block a user