mirror of
https://github.com/Bluewhale1337/ElvUIModernized.git
synced 2026-07-27 08:24:44 +00:00
optimizations
This commit is contained in:
@@ -9,7 +9,7 @@ local type = type
|
|||||||
local unpack = unpack
|
local unpack = unpack
|
||||||
local ceil, floor = math.ceil, math.floor
|
local ceil, floor = math.ceil, math.floor
|
||||||
local find, format, gfind, gsub, sub = string.find, string.format, string.gfind, string.gsub, string.sub
|
local find, format, gfind, gsub, sub = string.find, string.format, string.gfind, string.gsub, string.sub
|
||||||
local getn, setn, tinsert = table.getn, table.setn, table.insert
|
local concat, getn, setn = table.concat, table.getn, table.setn
|
||||||
|
|
||||||
math.huge = 1/0
|
math.huge = 1/0
|
||||||
string.gmatch = string.gfind
|
string.gmatch = string.gfind
|
||||||
@@ -29,11 +29,9 @@ function select(n, ...)
|
|||||||
error(format("bad argument #1 to 'select' (number expected, got %s)", n and type(n) or "no value"), 2)
|
error(format("bad argument #1 to 'select' (number expected, got %s)", n and type(n) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(n) == "string" then
|
if n == "#" then
|
||||||
return getn(arg)
|
return getn(arg)
|
||||||
end
|
elseif n == 1 then
|
||||||
|
|
||||||
if n == 1 then
|
|
||||||
return unpack(arg)
|
return unpack(arg)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -61,17 +59,11 @@ function string.join(delimiter, ...)
|
|||||||
error(format("bad argument #1 to 'join' (string expected, got %s)", delimiter and type(delimiter) or "no value"), 2)
|
error(format("bad argument #1 to 'join' (string expected, got %s)", delimiter and type(delimiter) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local size = getn(arg)
|
if getn(arg) == 0 then
|
||||||
if size == 0 then
|
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local text = arg[1]
|
return concat(arg, delimiter)
|
||||||
for i = 2, size do
|
|
||||||
text = text..delimiter..arg[i]
|
|
||||||
end
|
|
||||||
|
|
||||||
return text
|
|
||||||
end
|
end
|
||||||
strjoin = string.join
|
strjoin = string.join
|
||||||
|
|
||||||
@@ -84,19 +76,15 @@ function string.match(str, pattern, index)
|
|||||||
error(format("bad argument #3 to 'match' (number expected, got %s)", index and type(index) or "no value"), 2)
|
error(format("bad argument #3 to 'match' (number expected, got %s)", index and type(index) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
str = type(str) == "number" and tostring(str) or str
|
|
||||||
pattern = type(pattern) == "number" and tostring(pattern) or pattern
|
|
||||||
|
|
||||||
if type(index) == "string" then
|
|
||||||
index = index ~= "" and tonumber(index) or nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local i1, i2, match, match2 = find(str, pattern, index)
|
local i1, i2, match, match2 = find(str, pattern, index)
|
||||||
|
|
||||||
if not match and i2 and i2 >= i1 then
|
if not match and i2 and i2 >= i1 then
|
||||||
return sub(str, i1, i2)
|
return sub(str, i1, i2)
|
||||||
elseif match2 then
|
elseif match2 then
|
||||||
return select(3, find(str, pattern, index))
|
local matches = {find(str, pattern, index)}
|
||||||
|
tremove(matches, 2)
|
||||||
|
tremove(matches, 1)
|
||||||
|
return unpack(matches)
|
||||||
end
|
end
|
||||||
|
|
||||||
return match
|
return match
|
||||||
@@ -110,8 +98,6 @@ function string.split(delimiter, str)
|
|||||||
error(format("bad argument #2 to 'split' (string expected, got %s)", str and type(str) or "no value"), 2)
|
error(format("bad argument #2 to 'split' (string expected, got %s)", str and type(str) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
str = type(str) == "number" and tostring(str) or str
|
|
||||||
|
|
||||||
local fields = {}
|
local fields = {}
|
||||||
gsub(str, format("([^%s]+)", delimiter), function(c) fields[getn(fields) + 1] = c end)
|
gsub(str, format("([^%s]+)", delimiter), function(c) fields[getn(fields) + 1] = c end)
|
||||||
|
|
||||||
@@ -154,24 +140,21 @@ function string.trim(str, chars)
|
|||||||
error(format("bad argument #2 to 'trim' (string expected, got %s)", chars and type(chars) or "no value"), 2)
|
error(format("bad argument #2 to 'trim' (string expected, got %s)", chars and type(chars) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
str = type(str) == "number" and tostring(str) or str
|
|
||||||
|
|
||||||
if chars then
|
if chars then
|
||||||
chars = type(chars) == "number" and tostring(chars) or chars
|
|
||||||
|
|
||||||
local tokens = {}
|
local tokens = {}
|
||||||
|
local size = 0
|
||||||
|
|
||||||
for token in gfind(chars, "[%z\1-\255]") do
|
for token in gfind(chars, "[%z\1-\255]") do
|
||||||
tinsert(tokens, token)
|
size = size + 1
|
||||||
|
tokens[size] = token
|
||||||
end
|
end
|
||||||
|
|
||||||
local pattern = ""
|
local pattern = ""
|
||||||
local size = getn(tokens)
|
|
||||||
|
|
||||||
for i = 1, size do
|
for i = 1, size do
|
||||||
pattern = pattern..(escapeSequences[tokens[i]] or tokens[i]).."+"
|
pattern = pattern..(escapeSequences[tokens[i]] or tokens[i]).."+"
|
||||||
|
|
||||||
if size > 1 and i < size then
|
if i < size then
|
||||||
pattern = pattern.."|"
|
pattern = pattern.."|"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -180,16 +163,18 @@ function string.trim(str, chars)
|
|||||||
local patternEnd = loadstring("return \"^(.-)["..pattern.."]$\"")()
|
local patternEnd = loadstring("return \"^(.-)["..pattern.."]$\"")()
|
||||||
|
|
||||||
local trimed, x, y = 1
|
local trimed, x, y = 1
|
||||||
while trimed >= 1 do
|
while trimed > 0 do
|
||||||
str, x = gsub(str, patternStart, "%1")
|
str, x = gsub(str, patternStart, "%1")
|
||||||
str, y = gsub(str, patternEnd, "%1")
|
str, y = gsub(str, patternEnd, "%1")
|
||||||
trimed = x + y
|
trimed = x + y
|
||||||
end
|
end
|
||||||
|
|
||||||
return str
|
return str
|
||||||
else
|
elseif type(str) == "string" then
|
||||||
-- remove leading/trailing [space][tab][return][newline]
|
-- remove leading/trailing [space][tab][return][newline]
|
||||||
return gsub(str, "^%s*(.-)%s*$", "%1")
|
return gsub(str, "^%s*(.-)%s*$", "%1")
|
||||||
|
else
|
||||||
|
return tostring(str)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
strtrim = string.trim
|
strtrim = string.trim
|
||||||
@@ -245,6 +230,7 @@ function tostringall(...)
|
|||||||
return unpack(LOCAL_ToStringAllTemp)
|
return unpack(LOCAL_ToStringAllTemp)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local strjoin = strjoin
|
||||||
local LOCAL_PrintHandler = function(...)
|
local LOCAL_PrintHandler = function(...)
|
||||||
DEFAULT_CHAT_FRAME:AddMessage(strjoin(" ", tostringall(unpack(arg))))
|
DEFAULT_CHAT_FRAME:AddMessage(strjoin(" ", tostringall(unpack(arg))))
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user