Skip to content

Commit

Permalink
Reuse weak-table metatables
Browse files Browse the repository at this point in the history
  • Loading branch information
SinisterRectus committed Jan 7, 2020
1 parent 7f447d0 commit 0f401b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 2.8.1
- Multiple presences are now flattened into one
- Fixed typo in `Guild:splashURL`
- Fixed typo in `Guild.splashURL` result
- Fixed issue where `Ban` objects generated by `Guild:getBan` did not have the correct parent type
- Fixed crash when FFmpeg process would close before reading
- Removed FFI dependency in Date class
Expand Down
4 changes: 3 additions & 1 deletion libs/iterables/Cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ local null = json.null

local Cache = require('class')('Cache', Iterable)

local meta = {__mode = 'v'}

function Cache:__init(array, constructor, parent)
local objects = {}
for _, data in ipairs(array) do
Expand All @@ -21,7 +23,7 @@ function Cache:__init(array, constructor, parent)
self._objects = objects
self._constructor = constructor
self._parent = parent
self._deleted = setmetatable({}, {__mode = 'v'})
self._deleted = setmetatable({}, meta)
end

function Cache:__pairs()
Expand Down
4 changes: 3 additions & 1 deletion libs/iterables/WeakCache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ local Iterable = require('iterables/Iterable')

local WeakCache = require('class')('WeakCache', Cache)

local meta = {__mode = 'v'}

function WeakCache:__init(array, constructor, parent)
Cache.__init(self, array, constructor, parent)
setmetatable(self._objects, {__mode = 'v'})
setmetatable(self._objects, meta)
end

function WeakCache:__len() -- NOTE: _count is not accurate for weak caches
Expand Down

0 comments on commit 0f401b1

Please sign in to comment.