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
|
||||
local Stack = require('libmodal/src/utils/classes').new(nil)
|
||||
local Stack = require('libmodal.src.utils.classes').new()
|
||||
|
||||
--- @return libmodal.collections.Stack
|
||||
function Stack.new()
|
||||
return setmetatable({}, Stack)
|
||||
end
|
||||
|
||||
--- @return unknown top the foremost value of the stack
|
||||
--- @generic T
|
||||
--- @return T top the foremost value of the stack
|
||||
function Stack:peek()
|
||||
return self[#self]
|
||||
end
|
||||
|
||||
--- 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()
|
||||
return table.remove(self)
|
||||
end
|
||||
|
||||
--- 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)
|
||||
-- push to the stack
|
||||
self[#self + 1] = value
|
||||
table.insert(self, value)
|
||||
end
|
||||
|
||||
return Stack
|
||||
|
@ -1,8 +1,10 @@
|
||||
--- @class libmodal.collections
|
||||
--- @field private ParseTable libmodal.collections.ParseTable
|
||||
--- @field private Stack libmodal.collections.Stack
|
||||
return
|
||||
--- @field ParseTable libmodal.collections.ParseTable
|
||||
--- @field Stack libmodal.collections.Stack
|
||||
local collections =
|
||||
{
|
||||
ParseTable = require 'libmodal/src/collections/ParseTable',
|
||||
Stack = require 'libmodal/src/collections/Stack'
|
||||
ParseTable = require 'libmodal.src.collections.ParseTable',
|
||||
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
|
||||
local classes = {}
|
||||
local classes =
|
||||
{
|
||||
--- define a metatable.
|
||||
--- @param template? table the default value
|
||||
--- @return table class
|
||||
new = function(template)
|
||||
-- set self to `template`, or `{}` if nil.
|
||||
local self = template or {}
|
||||
|
||||
--- define a metatable.
|
||||
--- @param template? table the default value
|
||||
function classes.new(template)
|
||||
-- set self to `template`, or `{}` if nil.
|
||||
local self = template or {}
|
||||
|
||||
-- set `__index`.
|
||||
if not self.__index then
|
||||
-- set `__index`.
|
||||
self.__index = self
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
return self
|
||||
end,
|
||||
}
|
||||
|
||||
return classes
|
||||
|
Loading…
Reference in New Issue