Skip to content

Conversation

goran-w
Copy link
Contributor

@goran-w goran-w commented Jun 13, 2025

There's no need to populate a Dictionary just to diff the old and cur Lists of Changes (in the equal list-length case).

If there has been no changes in the working-copy between the two calls to QueryLocalChanges, we can assume that the items in the two lists are reported (by git-status) in equal sort-order. And consequently, if the Path value DOES differ between two items at equal index in the two equal-length lists, we can directly conclude that some change has occurred between these two calls.

Thus, we only need to loop through the successive list-indices (of the two equal-length lists), comparing the Path, Index and WorkTree values of the o and c items at each such index.

Loosely related to PR #1401 (where this refacoring was included but not merged).

* There's no need to populate a Dictionary just to diff the the "old" and "cur" Lists of Changes.
* If the two lists are of equal length and no change has occurred, we can assume that they are also reported in equal sort-order (by git-status).
* Thus, we only need to compare the two items at each successive index.
@goran-w goran-w changed the title Optimize the WorkingCopy.IsChanged() method Refactor: Optimize the WorkingCopy.IsChanged() method Jun 13, 2025
@love-linger love-linger self-assigned this Jun 13, 2025
@love-linger love-linger added the enhancement New feature or request label Jun 13, 2025
@love-linger love-linger merged commit 28844c5 into sourcegit-scm:develop Jun 13, 2025
13 checks passed
@goran-w goran-w deleted the optimize_workingcopy_ischanged branch June 13, 2025 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants