diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2008-08-09 18:59:37 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2008-08-09 18:59:37 +0000 |
commit | 2787a7f68896663647e19a1387195ae18db7d37a (patch) | |
tree | a8bea7c90ef79da1a5cb5e89dc818c4c119db633 /libs/core | |
parent | ba298a020bc033f526a0750caa24e9b098074674 (diff) |
* luci/libs: In luci.ip: __array16() does assert() already, so drop redundant sanity checks in add() and sub()
Diffstat (limited to 'libs/core')
-rw-r--r-- | libs/core/luasrc/ip.lua | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/libs/core/luasrc/ip.lua b/libs/core/luasrc/ip.lua index 02b4a66a6..bba701ae2 100644 --- a/libs/core/luasrc/ip.lua +++ b/libs/core/luasrc/ip.lua @@ -551,19 +551,17 @@ function cidr.add( self, amount, inplace ) local data = { unpack(self[2]) } local shorts = __array16( amount, self[1] ) - if shorts then - for pos = #data, 1, -1 do - local add = ( #shorts > 0 ) and table.remove( shorts, #shorts ) or 0 - if ( data[pos] + add ) > 0xFFFF then - data[pos] = ( data[pos] + add ) % 0xFFFF - if pos > 1 then - data[pos-1] = data[pos-1] + ( add - data[pos] ) - else - return nil - end + for pos = #data, 1, -1 do + local add = ( #shorts > 0 ) and table.remove( shorts, #shorts ) or 0 + if ( data[pos] + add ) > 0xFFFF then + data[pos] = ( data[pos] + add ) % 0xFFFF + if pos > 1 then + data[pos-1] = data[pos-1] + ( add - data[pos] ) else - data[pos] = data[pos] + add + return nil end + else + data[pos] = data[pos] + add end end @@ -584,19 +582,17 @@ function cidr.sub( self, amount, inplace ) local data = { unpack(self[2]) } local shorts = __array16( amount, self[1] ) - if shorts then - for pos = #data, 1, -1 do - local sub = ( #shorts > 0 ) and table.remove( shorts, #shorts ) or 0 - if ( data[pos] - sub ) < 0 then - data[pos] = ( sub - data[pos] ) % 0xFFFF - if pos > 1 then - data[pos-1] = data[pos-1] - ( sub + data[pos] ) - else - return nil - end + for pos = #data, 1, -1 do + local sub = ( #shorts > 0 ) and table.remove( shorts, #shorts ) or 0 + if ( data[pos] - sub ) < 0 then + data[pos] = ( sub - data[pos] ) % 0xFFFF + if pos > 1 then + data[pos-1] = data[pos-1] - ( sub + data[pos] ) else - data[pos] = data[pos] - sub + return nil end + else + data[pos] = data[pos] - sub end end |