git-svn: use sys* IO functions for reading rev_db
Using buffered IO for reading 40-41 bytes at a time isn't very efficient. Buffering writes for a short duration is alright since we close() right away and buffers will be flushed. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jan 31, 2007 at 17:57 UTC
ce4b4af7ff36d4e4999da937dffd2f9a3a420277
1 file changed
+9
-15
git-svn.perl
+9
-15
@@ -891,23 +891,20 @@ sub last_rev_commit {
891
my $rl;
892
open my $fh, '<', $self->{db_path} or
893
croak "$self->{db_path} not readable: $!\n";
894
- seek $fh, $offset, 2;
895
- $rl = readline $fh;
896
- defined $rl or return (undef, undef);
894
+ sysseek($fh, $offset, 2); # don't care for errors
895
+ sysread($fh, $rl, 41) == 41 or return (undef, undef);
896
chomp $rl;
898
- while (('0' x40) eq $rl && tell $fh != 0) {
897
+ while (('0' x40) eq $rl && sysseek($fh, 0, 1) != 0) {
898
$offset -= 41;
900
- seek $fh, $offset, 2;
901
- $rl = readline $fh;
902
- defined $rl or return (undef, undef);
899
+ sysseek($fh, $offset, 2); # don't care for errors
900
+ sysread($fh, $rl, 41) == 41 or return (undef, undef);
901
chomp $rl;
902
}
903
if ($c) {
904
die "$self->{db_path} and ", $self->refname,
905
" inconsistent!:\n$c != $rl\n";
906
}
909
- my $rev = tell $fh;
910
- croak $! if ($rev < 0);
907
+ my $rev = sysseek($fh, 0, 1) or croak $!;
908
$rev = ($rev - 41) / 41;
909
close $fh or croak $!;
910
($self->{last_rev}, $self->{last_commit}) = ($rev, $c);
@@ -1419,12 +1416,9 @@ sub rev_db_get {
1416
my $ret;
1417
my $offset = $rev * 41;
1418
open my $fh, '<', $self->{db_path} or croak $!;
1422
- if (seek $fh, $offset, 0) {
1423
- $ret = readline $fh;
1424
- if (defined $ret) {
1425
- chomp $ret;
1426
- $ret = undef if ($ret =~ /^0{40}$/);
1427
- }
1419
+ if (sysseek($fh, $offset, 0) == $offset) {
1420
+ my $read = sysread($fh, $ret, 40);
1421
+ $ret = undef if ($read != 40 || $ret eq ('0'x40));
1422
}
1423
close $fh or croak $!;
1424
$ret;