From ccaeb030f32283d3dd189c007524259f72d8a4cc Mon Sep 17 00:00:00 2001 From: aaron <83140718+centau@users.noreply.github.com> Date: Thu, 26 Dec 2024 21:17:14 +0000 Subject: [PATCH] Remove aggregate construction --- CHANGELOG.md | 4 ++++ src/apply.luau | 24 +----------------------- test/benchmark.luau | 34 ---------------------------------- test/tests.luau | 15 --------------- 4 files changed, 5 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca9bbb8..83b4399 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - A scope can no longer be destroyed while it is active. Strict mode will check for this. +### Removed + +- Aggregate construction when setting properties with `create()`. + -------------------------------------------------------------------------------- ## [0.3.1] - 2024-10-09 diff --git a/src/apply.luau b/src/apply.luau index 1598f3b..15246a6 100644 --- a/src/apply.luau +++ b/src/apply.luau @@ -62,22 +62,6 @@ local function return_caches(caches: typeof(free_caches) ) free_caches = caches end --- map of datatype names to class default constructor for aggregate init -local aggregates = {} -for name, class in { - CFrame = CFrame, - Color3 = Color3, - UDim = UDim, - UDim2 = UDim2, - Vector2 = Vector2, - Rect = Rect -} :: Map do - aggregates[name] = class.new -end - -aggregates.Vector3 = vector.create -aggregates.vector = vector.create - -- applies table of nested properties to an instance using full vide semantics local function apply(instance: T & Instance, properties: { [unknown]: unknown }): T if not properties then @@ -109,13 +93,7 @@ local function apply(instance: T & Instance, properties: { [unknown]: unknown nested_debug[depth][property] = true end - if type(value) == "table" then -- attempt aggregate init - local ctor = aggregates[typeof((instance :: any)[property])] - if ctor == nil then - throw(`cannot aggregate type {typeof(value)} for property {property}`) - end - (instance :: any)[property] = ctor(unpack(value :: {})) - elseif type(value) == "function" then + if type(value) == "function" then if typeof((instance :: any)[property]) == "RBXScriptSignal" then events[property] = value :: () -> () -- add event to buffer else diff --git a/test/benchmark.luau b/test/benchmark.luau index 524cea7..690c8b9 100644 --- a/test/benchmark.luau +++ b/test/benchmark.luau @@ -544,38 +544,4 @@ ROOT_BENCH("spring step", function() end) end) -TITLE "aggregate" - -do - -- the purpose of the two following benchmarks is to measure the overhead of - -- aggregate construction - ROOT_BENCH("set explicit vector", function() - local apply = require "../src/apply" - - local label = create "TextLabel" { - AnchorPoint = vector.create(1, 1, 1) - } - - for i = 1, START(N) do - apply(label, { - AnchorPoint = vector.create(i, i, i) - }) - end - end) - - ROOT_BENCH("set aggregate vector", function() - local apply = require "../src/apply" - - local label = create "TextLabel" { - AnchorPoint = vector.create(1, 1, 1) - } - - for i = 1, START(N) do - apply(label, { - AnchorPoint = { i, i, i } - }) - end - end) -end - return nil diff --git a/test/tests.luau b/test/tests.luau index a0ba2ff..85f5357 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -759,21 +759,6 @@ TEST("create()", wrap_root(function() CHECK(text.Text == "test") end - do CASE "aggregate construction" - local template = create "TextLabel" { - AnchorPoint = Vector2.new(), - Position = UDim2.new() - } - - local text = create(template) { - AnchorPoint = { 1, 2 }, - Position = { 3, 4 } - } - - CHECK(text.AnchorPoint == Vector2.new(1, 2)) - CHECK(text.Position == UDim2.new(3, 4)) - end - do CASE "nested precedence" local text = create "TextLabel" { {