|
|
ru.perl- RU.PERL ---------------------------------------------------------------------- From : Vladimir Podgorny 2:5020/400 07 Oct 2003 12:06:10 To : Konstantin Petrenko Subject : Re: оптимизация -------------------------------------------------------------------------------- Konstantin Petrenko <Konstantin.Petrenko@p1.f14.n5006.z2.fidonet.org> wrote: [...skipped...] Net::Netmask::match работает в 2.5 раза быстрее. RTFS Net::Netmatch: sub match { my ($this, $ip) = @_; my $i = quad2int($ip); my $imask = imask($this->{BITS}); if (($i & $imask) == $this->{IBASE}) { return (($i & ~ $imask) || "0 "); } else { return 0; } } sub quad2int { my @bytes = split(/\./,$_[0]); return undef unless @bytes == 4 && ! grep {!(/\d+$/ && $_<256)} @bytes; return unpack("N",pack("C4",@bytes)); } sub imask { return (2**32 -(2** (32- $_[0]))); } -- VP992-RIPE | Right becomes wrong, the left becomes the right... | (c) Dire Straits, "Brothers in arms" '84, "Ride across the river" --- ifmail v.2.15dev5 * Origin: Adamant ISP news server (2:5020/400) Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.perl/1203458e878ec.html, оценка из 5, голосов 10
|