From e0a61012b46cfe773e9a1561fce800f54c6e1763 Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Thu, 22 Sep 2016 17:27:50 -0700 Subject: [PATCH] more efficient Creep.prototype.getActiveBodyparts --- screeps-perf.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/screeps-perf.js b/screeps-perf.js index b767d7d..ed0d71f 100644 --- a/screeps-perf.js +++ b/screeps-perf.js @@ -19,6 +19,23 @@ module.exports = function(options) { lastMemoryCleanUp: Game.time }; + /** + * Creep method optimizations + */ + Creep.prototype.getActiveBodyparts = function (type) { + let count = 0; + for (let i = this.body.length; i-- > 0;) { + if (this.body[i].hits > 0) { + if (this.body[i].type == type) { + count++; + } + } else { + break; + } + } + return count; + }; + if (options.speedUpArrayFunctions || options.speedUpArrayFunctions === undefined) { Array.prototype.filter = function(callback, thisArg) { var results = [];