From e5ebda1b1e67cc019b32deba0ef3a5c500182c52 Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Thu, 26 Apr 2018 20:53:04 -0400 Subject: [PATCH] Significant performance improvement validating AUTOLOAD methods --- Changes | 1 + lib/SNMP/Info.pm | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Changes b/Changes index 95f5fe40..e4a22b1b 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,7 @@ Version 3.57 * #145 Patch for Huawei (robwwd) * #228 Huawei aggregate link support * POE and duplex admin support added to L3::Huawei + * Significant performance improvement validating AUTOLOAD methods [BUG FIXES] diff --git a/lib/SNMP/Info.pm b/lib/SNMP/Info.pm index 17b05139..735469f8 100644 --- a/lib/SNMP/Info.pm +++ b/lib/SNMP/Info.pm @@ -4679,16 +4679,26 @@ sub _validate_autoload_method { } - # If the parent of the leaf has indexes it is contained within a table - my $indexes = $SNMP::MIB{$oid}{'parent'}{'indexes'}; - my $table_leaf = 0; + my $table_leaf = 0; + + # This is an expensive check so we assume anything in the funcs and globals + # hashes are known. Only for actual MIB leafs should we have to check the + # MIB. If the parent of the leaf has indexes it is contained within a table. + if ($funcs->{$attr}) { + $table_leaf = 1; + } + elsif (!$globals->{$attr}) { - if ( !$globals->{$attr} - && ( ( defined $indexes && scalar( @{$indexes} ) > 0 ) - || $funcs->{$attr} )) - { - $table_leaf = 1; - } + # Prevent autovivification + if (exists $SNMP::MIB{$oid} && + exists $SNMP::MIB{$oid}{'parent'} && + exists $SNMP::MIB{$oid}{'parent'}{'indexes'} && + defined $SNMP::MIB{$oid}{'parent'}{'indexes'} && + scalar( @{$SNMP::MIB{$oid}{'parent'}{'indexes'}} ) > 0) + { + $table_leaf = 1; + } + } # Tag on .0 for %GLOBALS and single instance MIB leafs unless # the leaf ends in a digit or we are going to use for a set operation