rewrite(phase4): didnt think if global exists lol

This commit is contained in:
khtsly 2026-02-13 21:59:03 +07:00
parent 4af26f4d41
commit 81d3c540c1

View file

@ -1,30 +1,25 @@
--!optimize 2 --!optimize 2
--!native
--@EternityDev --@EternityDev
local BITS: number = 16 local BITS: number = 8
local MAX_VALUE: number = bit32.lshift(1, BITS) - 1 local MAX_VALUE: number = bit32.lshift(1, BITS) - 1
local cache: { [string]: number } = {} if not shared.__identifier_registry then
local hash: number = game.PlaceVersion + 5381 shared.__identifier_registry = {
local count: number = 0 cache = {} :: { [string]: number },
counter = 0,
return function(name: string): number }
local cached = cache[name] end
if cached then
return cached local registry = shared.__identifier_registry
end return function(name: string): number
if count >= 255 then -- 255 is safer from collision local cached = registry.cache[name]
warn("ran out of ids :(") if cached then
return 0 return cached
end end
local b: number = hash local id = registry.counter + 1
for i = 1, #name do assert(id <= MAX_VALUE, `Identifier overflow: exceeded {MAX_VALUE + 1} unique names.`)
b = bit32.bxor(bit32.lshift(b, 5) + b, string.byte(name, i)) registry.counter = id + 1
end registry.cache[name] = id
return id
local reduced = bit32.band(b, MAX_VALUE)
cache[name] = reduced
count += 1
return reduced
end end