Skip to content

Commit

Permalink
Merge pull request #13 from newhouse/newhouse/v4-range-efficiency
Browse files Browse the repository at this point in the history
keep Netmask map results around, instead of re-computing each time
  • Loading branch information
frenchbread authored Apr 16, 2021
2 parents 664a127 + 2d9c66c commit 6c6453b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const PRIVATE_IP_RANGES = [
'255.255.255.255/32'
]

function ipv4_check (ip_addr) {
const blocks = [...PRIVATE_IP_RANGES].map(ip_range => new Netmask(ip_range))
const NETMASK_RANGES = PRIVATE_IP_RANGES.map(ip_range => new Netmask(ip_range))

for (let r of blocks) {
function ipv4_check (ip_addr) {
for (let r of NETMASK_RANGES) {
if (r.contains(ip_addr)) return true
}

Expand Down

0 comments on commit 6c6453b

Please sign in to comment.