IPAddress#loopback? should consider ::ffff:127.0.0.1/104 loopback too#12783
IPAddress#loopback? should consider ::ffff:127.0.0.1/104 loopback too#12783straight-shoota merged 8 commits intocrystal-lang:masterfrom
IPAddress#loopback? should consider ::ffff:127.0.0.1/104 loopback too#12783Conversation
IPAddress#loopback? should consider ::ffff:127.0.0.1/104 loopback too
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
src/socket/address.cr
Outdated
| ipv6_addr8(addr) == StaticArray[0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 1_u8] | ||
| addr8 = ipv6_addr8(addr) | ||
| addr8 == StaticArray[0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 1_u8] || # "::1" | ||
| addr8.to_slice[0, 13] == Bytes[0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 255_u8, 255_u8, 127_u8] # "::ffff:127.0.0.1/104" |
There was a problem hiding this comment.
This should be turned into a constant to avoid having to allocate the Bytes on every call (and the StaticArray above too if you wish)
There was a problem hiding this comment.
Or StaticArray#to_slice? will only stack allocate.
There was a problem hiding this comment.
I think it might be simpler to turn the raw bytes into UInt64 or whatever and compare things against numbers. It should also be faster.
There was a problem hiding this comment.
Same speed for StaticArray[...]#to_slice and .unsafe_as(UInt128) (1ns to do the check), I guess it comes down to readability. See for comparison: 3663384
c128672 to
fe512dd
Compare
As they aren't supported in older crystal versions Co-authored-by: Johannes Müller <straightshoota@gmail.com>
fe512dd to
f9a212b
Compare
|
@carlhoerberg Something went wrong with your rebase. I suppose you intended to update the branch on master. But somewhow that got botched and there were some weird commits that don't belong here. |
No description provided.