-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ #33: Improved performance when get linked info by memoizing its result
- Loading branch information
1 parent
a85dc46
commit c42a03e
Showing
4 changed files
with
97 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
-------------------------------------- | ||
-- Imports | ||
-------------------------------------- | ||
---@class TodoAddon | ||
local TodoAddon = select(2, ...) | ||
|
||
-------------------------------------- | ||
-- Declarations | ||
-------------------------------------- | ||
TodoAddon.FunctionUtils = {} | ||
|
||
---@class FunctionUtils | ||
local FunctionUtils = TodoAddon.FunctionUtils | ||
|
||
local memoizedValues = {} | ||
|
||
-------------------------------------- | ||
-- TableUtils functions | ||
-------------------------------------- | ||
|
||
--- | ||
---Calls a function once and store its key value, if the function gets called again but the parameters haven't changed. | ||
---Instead of calling it again, it just return the previously calculated value | ||
---@generic T | ||
---@param execution fun(): T @A complex function that you want to Memoize | ||
---@param comparator any @The value used to decide wether or not the function should be called again | ||
---@param name string @A unique name for this memoization | ||
---@return T @The returned value from the executed function | ||
function FunctionUtils:Memoize(execution, comparator, name) | ||
if (memoizedValues[name] and memoizedValues[name].comparator == comparator) then | ||
return memoizedValues[name].result | ||
end | ||
|
||
memoizedValues[name] = { | ||
result = execution(), | ||
comparator = comparator | ||
} | ||
|
||
return memoizedValues[name].result | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<Ui xmlns="http://www.blizzard.com/wow/ui/" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ | ||
..\FrameXML\UI.xsd"> | ||
<Script file="functionUtils.lua"/> | ||
<Script file="tableUtils.lua"/> | ||
</Ui> |