From 3babadf4546b14c9f527fb4949d0d1cfefa6b105 Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Wed, 11 Nov 2020 01:42:09 -0800
Subject: [PATCH] Be a bit more efficient about calculating incest
 bonuses...don't bother computing relations for slaves that don't work
 together, since they'll never qualify.

---
 src/js/slaveCostJS.js | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/js/slaveCostJS.js b/src/js/slaveCostJS.js
index 3cf15015d3f..8fa439431be 100644
--- a/src/js/slaveCostJS.js
+++ b/src/js/slaveCostJS.js
@@ -1811,26 +1811,28 @@ globalThis.FResultArray = (function() {
 	 * @param {App.Entity.SlaveState} slave
 	 */
 	function calcWorksWithRelatives(slave) {
-		V.slaves.forEach(potentialRel => {
-			if (isParentP(slave, potentialRel) && sameAssignmentP(slave, potentialRel)) {
-				adjustFResult(`Works with their parent(s)`, 1);
-				if (incestBonus) {
-					adjustFResult(`Works with their parent(s): incest bonus`, 1);
+		for (const potentialRel of V.slaves) {
+			if (sameAssignmentP(slave, potentialRel)) {
+				if (isParentP(slave, potentialRel)) {
+					adjustFResult(`Works with their parent(s)`, 1);
+					if (incestBonus) {
+						adjustFResult(`Works with their parent(s): incest bonus`, 1);
+					}
 				}
-			}
-			if (isParentP(potentialRel, slave) && sameAssignmentP(slave, potentialRel)) {
-				adjustFResult(`Works with their kid(s)`, 1);
-				if (incestBonus) {
-					adjustFResult(`Works with their kid(s): incest bonus`, 1);
+				if (isParentP(potentialRel, slave)) {
+					adjustFResult(`Works with their kid(s)`, 1);
+					if (incestBonus) {
+						adjustFResult(`Works with their kid(s): incest bonus`, 1);
+					}
 				}
-			}
-			if (areSisters(slave, potentialRel) > 0 && sameAssignmentP(slave, potentialRel)) {
-				adjustFResult(`Works with their sibling(s)`, 1);
-				if (incestBonus) {
-					adjustFResult(`Works with their sibling(s): incest bonus`, 1);
+				if (areSisters(slave, potentialRel) > 0) {
+					adjustFResult(`Works with their sibling(s)`, 1);
+					if (incestBonus) {
+						adjustFResult(`Works with their sibling(s): incest bonus`, 1);
+					}
 				}
 			}
-		});
+		}
 	}
 
 	/**
-- 
GitLab