mirror of
https://github.com/imezx/Warp.git
synced 2026-03-18 00:44:16 +00:00
rewrite(phase4): add count validation
This commit is contained in:
parent
219b62b6d2
commit
36b03dec02
1 changed files with 6 additions and 0 deletions
|
|
@ -6,12 +6,17 @@ local MAX_VALUE: number = bit32.lshift(1, BITS) - 1
|
||||||
|
|
||||||
local cache: { [string]: number } = {}
|
local cache: { [string]: number } = {}
|
||||||
local hash: number = game.PlaceVersion + 5381
|
local hash: number = game.PlaceVersion + 5381
|
||||||
|
local count: number = 0
|
||||||
|
|
||||||
return function(name: string): number
|
return function(name: string): number
|
||||||
local cached = cache[name]
|
local cached = cache[name]
|
||||||
if cached then
|
if cached then
|
||||||
return cached
|
return cached
|
||||||
end
|
end
|
||||||
|
if count >= MAX_VALUE then
|
||||||
|
warn("ran out of ids :(")
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
local b: number = hash
|
local b: number = hash
|
||||||
for i = 1, #name do
|
for i = 1, #name do
|
||||||
|
|
@ -20,5 +25,6 @@ return function(name: string): number
|
||||||
|
|
||||||
local reduced = bit32.band(b, MAX_VALUE)
|
local reduced = bit32.band(b, MAX_VALUE)
|
||||||
cache[name] = reduced
|
cache[name] = reduced
|
||||||
|
count += 1
|
||||||
return reduced
|
return reduced
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue