From cccd4b3647da456d154af85535061da0844337d9 Mon Sep 17 00:00:00 2001 From: Mohhay <63205995+MohhayScripts@users.noreply.github.com> Date: Mon, 27 Nov 2023 23:14:03 +0100 Subject: [PATCH 1/3] Changed :format() with string.format() for performance reasons --- source/main.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/main.lua b/source/main.lua index ff14a4b..3768ce9 100644 --- a/source/main.lua +++ b/source/main.lua @@ -91,7 +91,7 @@ local ChalkObject = {}; ChalkObject.__index = ChalkObject; local function GenerateCustomHandlerFunction(Type) return function(Argument) - local FormatStart = Formats[Type].Start:format(Argument); + local FormatStart = string.format(Formats[Type].Start, Argument); return function(String) return `{FormatStart}{String}{Formats[Type].End}` @@ -112,7 +112,7 @@ local function GenerateColorFunction(Color) local G = math.floor(Color.g * 255); local B = math.floor(Color.b * 255); - local FormatStart = Formats.FONT_COLOR_RGB.Start:format(R, G, B); + local FormatStart = string.format(Formats.FONT_COLOR_RGB.Start, R, G, B); return `{FormatStart}{String}{Formats.FONT_COLOR_RGB.End}` end From bf4ed456b78c54647ebb189f6f05ddab23888cba Mon Sep 17 00:00:00 2001 From: Mohhay <63205995+MohhayScripts@users.noreply.github.com> Date: Mon, 27 Nov 2023 23:18:11 +0100 Subject: [PATCH 2/3] Added various other performance improvements --- source/main.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/main.lua b/source/main.lua index 3768ce9..e1531b8 100644 --- a/source/main.lua +++ b/source/main.lua @@ -121,7 +121,7 @@ end local function ValidateHex(String) if typeof(String) ~= "string" then return end - String = String:gsub("#", "") + String = string.gsub(String, "#", "") return string.match(String, `^%x%x%x%x%x%x$`) end @@ -138,7 +138,7 @@ local CustomHandler = { local Thickness = Data.Thickness or 1; local transparency = Data.Transparency or 0; - local FormatStart = Formats.STROKE.Start:format(Color, Joins, Thickness, transparency); + local FormatStart = string.format(Formats.STROKE.Start, Color, Joins, Thickness, transparency); return function(String) return `{FormatStart}{String}{Formats.STROKE.End}` @@ -156,8 +156,8 @@ local CustomHandler = { (IsHex and Color3.fromHex(FirstArg)) or Color3.fromRGB(FirstArg, Args[2], Args[3]); - local FormatStart = (IsHex and Formats.FONT_COLOR_HEX.Start:format(FirstArg:gsub("#", ""))) or - Formats.FONT_COLOR_RGB.Start:format(math.floor(Color.R * 255), math.floor(Color.G * 255), math.floor(Color.B * 255)); + local FormatStart = (IsHex and string.format(Formats.FONT_COLOR_HEX.Start, string.gsub(FirstArg, "#", ""))) or + string.format(Formats.FONT_COLOR_RGB.Start, math.floor(Color.R * 255), math.floor(Color.G * 255), math.floor(Color.B * 255)); return function(String) return `{FormatStart}{String}{Formats.FONT_COLOR_RGB.End}` @@ -182,12 +182,12 @@ for Index = 1, BrickColorCount do local G = math.floor(BrickColor.g * 255); local B = math.floor(BrickColor.b * 255); - local FormatStart = Formats.FONT_COLOR_RGB.Start:format(R, G, B); + local FormatStart = string.format(Formats.FONT_COLOR_RGB.Start, R, G, B); return `{FormatStart}{String}{Formats.FONT_COLOR_RGB.End}` end - ChalkData[BrickColor.Name:lower()] = Function + ChalkData[string.lower(BrickColor.Name)] = Function ChalkData[BrickColor.Name] = Function ChalkData[BrickColor] = Function end From 7e4ef88ecac512956b46264518968bfe48459024 Mon Sep 17 00:00:00 2001 From: Mohhay <63205995+MohhayScripts@users.noreply.github.com> Date: Mon, 27 Nov 2023 23:26:56 +0100 Subject: [PATCH 3/3] More unnoticeable performance improvements cause why not --- source/main.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/main.lua b/source/main.lua index e1531b8..5de1130 100644 --- a/source/main.lua +++ b/source/main.lua @@ -123,7 +123,7 @@ local function ValidateHex(String) String = string.gsub(String, "#", "") - return string.match(String, `^%x%x%x%x%x%x$`) + return string.match(String, `^%x%x%x%x%x%x$`) end local CustomHandler = { @@ -220,7 +220,7 @@ function ChalkObject.new(FirstObject) NextCall = nil; - return Call(unpack(Arguments)); + return Call(table.unpack(Arguments)); end local Results = {}; @@ -233,7 +233,7 @@ function ChalkObject.new(FirstObject) table.insert(Results, String); end - return unpack(Results); + return table.unpack(Results); end function Meta:__index(Index)