mirror of
https://github.com/imezx/Warp.git
synced 2026-03-18 00:44:16 +00:00
rewrite(phase4): fix identifier shifting by 2
This commit is contained in:
parent
e4184709bd
commit
b6fbc08111
1 changed files with 5 additions and 5 deletions
|
|
@ -23,19 +23,19 @@ return function(name: string): number
|
||||||
if cached then
|
if cached then
|
||||||
return cached
|
return cached
|
||||||
end
|
end
|
||||||
|
|
||||||
local b: number = hash
|
local b: number = hash
|
||||||
for i = 1, #name do
|
for i = 1, #name do
|
||||||
b = bit32.bxor(bit32.lshift(b, 5) + b, string.byte(name, i))
|
b = bit32.bxor(bit32.lshift(b, 5) + b, string.byte(name, i))
|
||||||
end
|
end
|
||||||
local reduced = bit32.band(b, MAX_VALUE)
|
|
||||||
if reduced < 2 then
|
local reduced: number = (b % (MAX_VALUE - 2)) + 2
|
||||||
reduced += 2
|
|
||||||
end
|
|
||||||
local existing = used[reduced]
|
local existing = used[reduced]
|
||||||
if existing and existing ~= name then
|
if existing and existing ~= name then
|
||||||
error(`[Warp] Hash collision: "{name}" & "{existing}" both map to ID {reduced}. Rename one.`)
|
error(`[Warp] Hash collision: "{name}" & "{existing}" both map to ID {reduced}. Rename one.`)
|
||||||
end
|
end
|
||||||
used[name] = reduced
|
|
||||||
|
used[reduced] = name
|
||||||
cache[name] = reduced
|
cache[name] = reduced
|
||||||
count += 1
|
count += 1
|
||||||
return reduced
|
return reduced
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue