]> git.proxmox.com Git - pve-storage.git/commitdiff
avoid unecessary try for over optimization
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 12 Nov 2020 16:31:16 +0000 (17:31 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 12 Nov 2020 16:31:26 +0000 (17:31 +0100)
That was lots of code and hash map touching for the case where one
avoided a extra stat, which result probably was in the page cache
anyway, for the case that a backup has a comment.

A case which is rather  be unlikely - comments are normally done for
the occasional explicit backup (e.g., before major upgrade, before a
configuration change in that guest, ...), at least not worth some
relatively complicated effort making that sub harder to read and
maintain.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/Storage/Plugin.pm

index 00ce9cb3c1230950906b1d358cd7c4fb552ec729..b4f3be860f98d25732e1575f08b084bca33aea45 100644 (file)
@@ -989,18 +989,7 @@ my $get_subdir_files = sub {
 
     my $res = [];
 
-    my $has_comment = {};
-
     foreach my $fn (<$path/*>) {
-
-       if (COMMENT_EXT eq substr($fn, -length(COMMENT_EXT))) {
-           my $real_fn = substr($fn, 0, length($fn) -  length(COMMENT_EXT));
-           if (!defined($has_comment->{$real_fn})) {
-               $has_comment->{$real_fn} = (-f $fn);
-           }
-           next; # we do not need to do anything with comments themselves
-       }
-
        my $st = File::stat::stat($fn);
 
        next if (!$st || S_ISDIR($st->mode));
@@ -1034,11 +1023,7 @@ my $get_subdir_files = sub {
            }
 
            my $comment_fn = $original.COMMENT_EXT;
-           if (!defined($has_comment->{$original})) {
-               $has_comment->{$original} = (-f $comment_fn);
-           }
-
-           if ($has_comment->{$original}) {
+           if (-f $comment_fn) {
                my $comment = PVE::Tools::file_read_firstline($comment_fn);
                $info->{comment} = $comment if defined($comment);
            }