Skip to content

Commit aa32c28

Browse files
committed
ye
1 parent bccd9a7 commit aa32c28

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/shape/Grid.luau

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ function Grid.of (min: number, max: number, step: number, wraps: boolean?): Grid
102102
local under = min - room
103103
local over = max + room
104104

105+
--[[
106+
A grid from zero at a whole step is its own index, so the shift and the division are a
107+
subtraction of nothing and a division by one. Written apart rather than branched inside,
108+
since the branch would then be taken once a field on every frame.
109+
]]
110+
if min == 0 and step == 1 then
111+
local function toIndex (value: any): number?
112+
if type (value) ~= "number" then return nil end
113+
if not (value >= under and value <= over) then return nil end
114+
return math.clamp (math.round (value), 0, span)
115+
end
116+
117+
return {
118+
span = span,
119+
width = width,
120+
plain = true,
121+
whole = span == bit32.lshift (1, width) - 1,
122+
toIndex = toIndex,
123+
fromIndex = fromIndex,
124+
}
125+
end
126+
105127
local function toIndex (value: any): number?
106128
if type (value) ~= "number" then return nil end
107129
if not (value >= under and value <= over) then return nil end
@@ -111,7 +133,7 @@ function Grid.of (min: number, max: number, step: number, wraps: boolean?): Grid
111133
return {
112134
span = span,
113135
width = width,
114-
plain = min == 0 and step == 1,
136+
plain = false,
115137
whole = span == bit32.lshift (1, width) - 1,
116138
toIndex = toIndex,
117139
fromIndex = fromIndex,

src/shape/emit/Word.luau

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ function Word.emit (of: Ir.Word, paths: Serial.Interner, expected: Serial.Intern
7878
if spans[index] == 0 then table.insert (empties, index) end
7979
end
8080

81+
-- Whether there are any, since a walk over none is one a decode takes for nothing.
82+
local barren = #empties > 0
83+
8184
-- Per join, in the order the region reads its fields.
8285
local reach = #joins
8386
local starts = table.create (reach, 0)
@@ -193,8 +196,10 @@ function Word.emit (of: Ir.Word, paths: Serial.Interner, expected: Serial.Intern
193196
left there, and a field that straddles two windows meets its low piece first.
194197
]]
195198
local function unpack (b: buffer, pos: number, into: any, slots: { number }, held: { any }): any
196-
for _, leaf in empties do
197-
slots[leaf] = 0
199+
if barren then
200+
for _, leaf in empties do
201+
slots[leaf] = 0
202+
end
198203
end
199204

200205
for index = 1, windows do

0 commit comments

Comments
 (0)