]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Config.pm
update copyrights for 2021
[public-inbox.git] / lib / PublicInbox / Config.pm
index 60107d455d5e36ed42c218285887c3ee7f26da9d..4f63bc937667d04a468d4152256ef99164d69d17 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2014-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Used throughout the project for reading configuration
@@ -132,13 +132,14 @@ sub default_file {
 
 sub config_fh_parse ($$$) {
        my ($fh, $rs, $fs) = @_;
-       my (%rv, %section_seen, @section_order, $line, $k, $v, $section, $cur);
+       my (%rv, %seen, @section_order, $line, $k, $v, $section, $cur, $i);
        local $/ = $rs;
-       while (defined($line = <$fh>)) { # performance critical with giant configs
-               chomp $line;
-               ($k, $v) = split($fs, $line, 2);
+       while (defined($line = <$fh>)) { # perf critical with giant configs
+               $i = index($line, $fs);
+               $k = substr($line, 0, $i);
+               $v = substr($line, $i + 1, -1); # chop off $fs
                $section = substr($k, 0, rindex($k, '.'));
-               $section_seen{$section} //= push(@section_order, $section);
+               $seen{$section} //= push(@section_order, $section);
 
                if (defined($cur = $rv{$k})) {
                        if (ref($cur) eq "ARRAY") {
@@ -160,7 +161,7 @@ sub git_config_dump {
        return {} unless -e $file;
        my $cmd = [ qw(git config -z -l --includes), "--file=$file" ];
        my $fh = popen_rd($cmd);
-       my $rv = config_fh_parse($fh, "\0", qr/\n/);
+       my $rv = config_fh_parse($fh, "\0", "\n");
        close $fh or die "failed to close (@$cmd) pipe: $?";
        $rv;
 }