perf: general improvements
I forgot to break it up into individual commits, and I ain't going backwards now.pull/20/head
parent
e535c17e84
commit
8c164b811d
@ -1,27 +1,30 @@
|
|||||||
--- @class libmodal.collections.Stack
|
--- @class libmodal.collections.Stack
|
||||||
local Stack = require('libmodal/src/utils/classes').new(nil)
|
local Stack = require('libmodal.src.utils.classes').new()
|
||||||
|
|
||||||
--- @return libmodal.collections.Stack
|
--- @return libmodal.collections.Stack
|
||||||
function Stack.new()
|
function Stack.new()
|
||||||
return setmetatable({}, Stack)
|
return setmetatable({}, Stack)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @return unknown top the foremost value of the stack
|
--- @generic T
|
||||||
|
--- @return T top the foremost value of the stack
|
||||||
function Stack:peek()
|
function Stack:peek()
|
||||||
return self[#self]
|
return self[#self]
|
||||||
end
|
end
|
||||||
|
|
||||||
--- remove the foremost value from the stack and return it.
|
--- remove the foremost value from the stack and return it.
|
||||||
--- @return unknown top the foremost value of the stack
|
--- @generic T
|
||||||
|
--- @return T top the foremost value of the stack
|
||||||
function Stack:pop()
|
function Stack:pop()
|
||||||
return table.remove(self)
|
return table.remove(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- push some `value` on to the stack.
|
--- push some `value` on to the stack.
|
||||||
--- @param value unknown the value to push onto the stack.
|
--- @generic T
|
||||||
|
--- @param value T the value to push onto the stack.
|
||||||
function Stack:push(value)
|
function Stack:push(value)
|
||||||
-- push to the stack
|
-- push to the stack
|
||||||
self[#self + 1] = value
|
table.insert(self, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Stack
|
return Stack
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
--- @class libmodal.collections
|
--- @class libmodal.collections
|
||||||
--- @field private ParseTable libmodal.collections.ParseTable
|
--- @field ParseTable libmodal.collections.ParseTable
|
||||||
--- @field private Stack libmodal.collections.Stack
|
--- @field Stack libmodal.collections.Stack
|
||||||
return
|
local collections =
|
||||||
{
|
{
|
||||||
ParseTable = require 'libmodal/src/collections/ParseTable',
|
ParseTable = require 'libmodal.src.collections.ParseTable',
|
||||||
Stack = require 'libmodal/src/collections/Stack'
|
Stack = require 'libmodal.src.collections.Stack'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return collections
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
--- @class libmodal.utils.Indicator
|
|
||||||
--- @field hl string the highlight group to use when printing `str`
|
|
||||||
--- @field str string the text to write
|
|
||||||
local Indicator = {}
|
|
||||||
|
|
||||||
--- @param highlight_group string the highlight group to use when printing `str`
|
|
||||||
--- @param str string what to print
|
|
||||||
--- @return libmodal.utils.Indicator
|
|
||||||
function Indicator.new(highlight_group, str)
|
|
||||||
return {hl = highlight_group, str = str}
|
|
||||||
end
|
|
||||||
|
|
||||||
return Indicator
|
|
@ -1,18 +1,18 @@
|
|||||||
--- @class libmodal.utils.classes
|
--- @class libmodal.utils.classes
|
||||||
local classes = {}
|
local classes =
|
||||||
|
{
|
||||||
--- define a metatable.
|
--- define a metatable.
|
||||||
--- @param template? table the default value
|
--- @param template? table the default value
|
||||||
function classes.new(template)
|
--- @return table class
|
||||||
|
new = function(template)
|
||||||
-- set self to `template`, or `{}` if nil.
|
-- set self to `template`, or `{}` if nil.
|
||||||
local self = template or {}
|
local self = template or {}
|
||||||
|
|
||||||
-- set `__index`.
|
-- set `__index`.
|
||||||
if not self.__index then
|
|
||||||
self.__index = self
|
self.__index = self
|
||||||
end
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
return classes
|
return classes
|
||||||
|
Loading…
Reference in New Issue