@@ -4228,6 +4228,37 @@ local function itemChangesPassiveTree(item)
42284228 and (item .jewelData .intuitiveLeapLike or item .jewelData .impossibleEscapeKeystone )))
42294229end
42304230
4231+ local function getStoredItemId (itemsTab , item )
4232+ if not item then
4233+ return " "
4234+ end
4235+ local itemId = item .id
4236+ if itemId and itemsTab .items [itemId ] == item then
4237+ return tostring (itemId )
4238+ end
4239+ end
4240+
4241+ local function getJewelComparisonOutputCache (itemsTab )
4242+ local outputRevision = itemsTab .build and itemsTab .build .outputRevision or 0
4243+ local cache = itemsTab .jewelComparisonOutputCache
4244+ if not cache or cache .outputRevision ~= outputRevision then
4245+ cache = {
4246+ outputRevision = outputRevision ,
4247+ outputs = { },
4248+ }
4249+ itemsTab .jewelComparisonOutputCache = cache
4250+ end
4251+ return cache
4252+ end
4253+
4254+ local function getJewelComparisonOutputCacheKey (itemsTab , compareSlot , replacementItem )
4255+ local replacementItemId = getStoredItemId (itemsTab , replacementItem )
4256+ if not replacementItemId then
4257+ return
4258+ end
4259+ return tostring (compareSlot .slotName ) .. " :" .. tostring (compareSlot .nodeId or " " ) .. " :" .. tostring (compareSlot .selItemId or " " ) .. " :" .. replacementItemId
4260+ end
4261+
42314262-- These jewels can replace passive nodes or disconnect allocated passives, so
42324263-- rebuild the passive tree before comparing their stats.
42334264-- Keep this list in sync with PassiveSpec's constructor, Init, and Select*
@@ -5079,13 +5110,27 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode, maxWidth)
50795110
50805111 tooltip :AddLine (14 , colorCodes .TIP .. " Tip: Press Ctrl+D" .. itemTabHint .. " to disable the display of stat differences." )
50815112
5082- local function getReplacedItemAndOutput (compareSlot , selItem , useJewelComparisonSpecCache )
5113+ local function getReplacedItemAndOutput (compareSlot , selItem , useJewelComparisonSpecCache , useJewelComparisonOutputCache )
50835114 selItem = selItem or self .items [compareSlot .selItemId ]
50845115 local override = { repSlotName = compareSlot .slotName , repItem = item ~= selItem and item or nil }
5116+ local outputCache
5117+ local outputCacheKey
50855118 if compareSlot .nodeId and (itemChangesPassiveTree (selItem ) or itemChangesPassiveTree (item )) then
5119+ if useJewelComparisonOutputCache then
5120+ outputCacheKey = getJewelComparisonOutputCacheKey (self , compareSlot , override .repItem )
5121+ if outputCacheKey then
5122+ outputCache = getJewelComparisonOutputCache (self )
5123+ if outputCache .outputs [outputCacheKey ] then
5124+ return selItem , outputCache .outputs [outputCacheKey ]
5125+ end
5126+ end
5127+ end
50865128 override .spec = buildSpecForJewelComparison (self , compareSlot , override .repItem , useJewelComparisonSpecCache )
50875129 end
50885130 local output = calcFunc (override )
5131+ if outputCacheKey then
5132+ outputCache .outputs [outputCacheKey ] = output
5133+ end
50895134 return selItem , output
50905135 end
50915136 local function addCompareForSlot (compareSlot , selItem , output , useJewelComparisonSpecCache )
@@ -5127,7 +5172,7 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode, maxWidth)
51275172 local slots = {}
51285173 for _ , slotEntry in ipairs (slotCandidates ) do
51295174 if not isLimitedUniqueAtLimit or slotEntry .isSameUnique then
5130- local _ , output = getReplacedItemAndOutput (slotEntry .compareSlot , slotEntry .selItem )
5175+ local _ , output = getReplacedItemAndOutput (slotEntry .compareSlot , slotEntry .selItem , nil , true )
51315176 slotEntry .output = output
51325177 table.insert (slots , slotEntry )
51335178 end
0 commit comments