* luci/libs: In luci.ip: __array16() does assert() already, so drop redundant sanity checks in add() and sub()
This commit is contained in:
parent
ba298a020b
commit
2787a7f688
1 changed files with 18 additions and 22 deletions
|
@ -551,19 +551,17 @@ function cidr.add( self, amount, inplace )
|
||||||
local data = { unpack(self[2]) }
|
local data = { unpack(self[2]) }
|
||||||
local shorts = __array16( amount, self[1] )
|
local shorts = __array16( amount, self[1] )
|
||||||
|
|
||||||
if shorts then
|
for pos = #data, 1, -1 do
|
||||||
for pos = #data, 1, -1 do
|
local add = ( #shorts > 0 ) and table.remove( shorts, #shorts ) or 0
|
||||||
local add = ( #shorts > 0 ) and table.remove( shorts, #shorts ) or 0
|
if ( data[pos] + add ) > 0xFFFF then
|
||||||
if ( data[pos] + add ) > 0xFFFF then
|
data[pos] = ( data[pos] + add ) % 0xFFFF
|
||||||
data[pos] = ( data[pos] + add ) % 0xFFFF
|
if pos > 1 then
|
||||||
if pos > 1 then
|
data[pos-1] = data[pos-1] + ( add - data[pos] )
|
||||||
data[pos-1] = data[pos-1] + ( add - data[pos] )
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
data[pos] = data[pos] + add
|
return nil
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
data[pos] = data[pos] + add
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -584,19 +582,17 @@ function cidr.sub( self, amount, inplace )
|
||||||
local data = { unpack(self[2]) }
|
local data = { unpack(self[2]) }
|
||||||
local shorts = __array16( amount, self[1] )
|
local shorts = __array16( amount, self[1] )
|
||||||
|
|
||||||
if shorts then
|
for pos = #data, 1, -1 do
|
||||||
for pos = #data, 1, -1 do
|
local sub = ( #shorts > 0 ) and table.remove( shorts, #shorts ) or 0
|
||||||
local sub = ( #shorts > 0 ) and table.remove( shorts, #shorts ) or 0
|
if ( data[pos] - sub ) < 0 then
|
||||||
if ( data[pos] - sub ) < 0 then
|
data[pos] = ( sub - data[pos] ) % 0xFFFF
|
||||||
data[pos] = ( sub - data[pos] ) % 0xFFFF
|
if pos > 1 then
|
||||||
if pos > 1 then
|
data[pos-1] = data[pos-1] - ( sub + data[pos] )
|
||||||
data[pos-1] = data[pos-1] - ( sub + data[pos] )
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
data[pos] = data[pos] - sub
|
return nil
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
data[pos] = data[pos] - sub
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue