Skip to content

Commit 5d055c4

Browse files
committed
Mini Optimization: Avoid stating the file twice
1 parent e815d78 commit 5d055c4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/index.dart

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ extension Index on GitRepository {
3333
) {
3434
filePath = normalizePath(filePath);
3535

36-
var file = fs.file(filePath);
37-
if (!file.existsSync()) {
36+
var stat = stdlibc.stat(filePath);
37+
if (stat == null) {
3838
throw GitFileNotFound(filePath);
3939
}
4040

@@ -45,7 +45,6 @@ extension Index on GitRepository {
4545
// LB: Wait is this a linear search over all files??
4646
// Maybe... but omitting it fully does not speed things up.
4747
var ei = index.entries.indexWhere((e) => e.path == pathSpec);
48-
var stat = stdlibc.stat(filePath)!;
4948
if (ei != -1) {
5049
var entry = index.entries[ei];
5150
if (entry.cTime.isAtSameMomentAs(stat.st_ctim) &&
@@ -58,7 +57,7 @@ extension Index on GitRepository {
5857
}
5958
}
6059

61-
var data = file.readAsBytesSync();
60+
var data = fs.file(filePath).readAsBytesSync();
6261
var blob = GitBlob(data, null); // Hash the file (takes time!)
6362
var hash = objStorage.writeObject(blob);
6463

0 commit comments

Comments
 (0)