Skip to content

Commit

Permalink
Mini Optimization: Avoid stating the file twice
Browse files Browse the repository at this point in the history
  • Loading branch information
vHanda committed Aug 24, 2024
1 parent e815d78 commit 5d055c4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ extension Index on GitRepository {
) {
filePath = normalizePath(filePath);

var file = fs.file(filePath);
if (!file.existsSync()) {
var stat = stdlibc.stat(filePath);
if (stat == null) {
throw GitFileNotFound(filePath);
}

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

var data = file.readAsBytesSync();
var data = fs.file(filePath).readAsBytesSync();
var blob = GitBlob(data, null); // Hash the file (takes time!)
var hash = objStorage.writeObject(blob);

Expand Down

0 comments on commit 5d055c4

Please sign in to comment.