@@ -31,7 +31,9 @@ local TalismanOmega_sizeof = assert(ffi.sizeof("struct TalismanOmega"))
3131--- @operator mod (t.Omega | number ): t.Omega
3232--- @operator pow (t.Omega | number ): t.Omega
3333--- @operator unm (): t.Omega
34- local Big = {}
34+ local Big = {
35+ created_instances = 0
36+ }
3537;(Big ).array = {} -- lsp hack, assign without recognized by lsp
3638
3739OmegaMeta = {
@@ -50,13 +52,18 @@ _G.Big = Big
5052local B = {}
5153
5254-- prevent multiple allocation of same number at a frame
55+ --- @class _t.OmegaCache
56+ --- @field list table<number , t.Omega> persisting list
57+ --- @field current table<number , t.Omega> created omegas in this frame , move to old on next frame
58+ --- @field old table<number , t.Omega> created omegas in previous frame , cleared on next frame
5359local caches = {
54- --- @type table<number , t.Omega>
5560 list = {},
56- --- @type table<number , number>
57- frames = {}
61+ current = {},
62+ currentcount = {},
5863}
5964
65+ Big .caches = caches
66+
6067-- prevent overrides
6168local type = type
6269local _math = math
100107--- @param noNormalize ? boolean
101108--- @return t.Omega
102109function Big :new (arr , sign , noNormalize )
110+ Big .created_instances = Big .created_instances + 1
111+
103112 --- @type t.Omega
104113 local obj = TalismanOmega () --- @diagnostic disable-line
105114 obj .asize = 1
@@ -116,12 +125,12 @@ function Big:create(input, sign)
116125 if obj then return obj end
117126 if input ~= input then return B .NaN end
118127
119- local obj = Big :new ({input }, input < 0 and - 1 or 1 )
120- caches .frames [input ] = (caches .frames [input ] or 0 ) + 1
121- if caches .frames [input ] > 100 then
122- caches .frames [input ] = nil
128+ obj = caches .current [input ] or Big :new ({input }, input < 0 and - 1 or 1 )
129+ caches .currentcount [input ] = (caches .currentcount [input ] or 0 ) + 1
130+ if caches .currentcount [input ] > 50 then
123131 caches .list [input ] = obj
124132 end
133+
125134 return obj
126135 elseif type (input ) == " string" then
127136 return Big :parse (input )
@@ -1618,9 +1627,15 @@ end
16181627
16191628if love then
16201629
1630+ local nextclear = 0
16211631local update = love .update
16221632function love .update (...)
1623- caches .frames = {}
1633+ if G .TIMERS .REAL > nextclear or G .TIMERS .REAL < nextclear - 2 then
1634+ caches .current = {}
1635+ caches .currentcount = {}
1636+ nextclear = G .TIMERS .REAL + 1
1637+ end
1638+
16241639 return update (... )
16251640end
16261641
0 commit comments