Skip to content

Commit 31c3e6a

Browse files
committed
Switches to use UriSet to remove duplicates
1 parent c7619f5 commit 31c3e6a

File tree

5 files changed

+38
-20
lines changed

5 files changed

+38
-20
lines changed

src/git/models/repository.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import type { RepoComparisonKey } from '../../repositories';
1111
import { asRepoComparisonKey } from '../../repositories';
1212
import { executeActionCommand } from '../../system/-webview/command';
1313
import { configuration } from '../../system/-webview/configuration';
14+
import { UriSet } from '../../system/-webview/uriMap';
1415
import { getScopedCounter } from '../../system/counter';
1516
import { gate } from '../../system/decorators/-webview/gate';
1617
import { memoize } from '../../system/decorators/-webview/memoize';
1718
import { debug, log, logName } from '../../system/decorators/log';
1819
import type { Deferrable } from '../../system/function/debounce';
1920
import { debounce } from '../../system/function/debounce';
20-
import { filter, groupByMap, join, min, some } from '../../system/iterable';
21+
import { filter, groupByMap, join, map, min, some } from '../../system/iterable';
2122
import { getLoggableName, Logger } from '../../system/logger';
2223
import { getLogScope, startLogScope } from '../../system/logger.scope';
2324
import { updateRecordValue } from '../../system/object';
@@ -139,7 +140,7 @@ export class RepositoryChangeEvent {
139140

140141
export interface RepositoryFileSystemChangeEvent {
141142
readonly repository: Repository;
142-
readonly uris: Uri[];
143+
readonly uris: UriSet;
143144
}
144145

145146
const instanceCounter = getScopedCounter();
@@ -416,8 +417,8 @@ export class Repository implements Disposable {
416417
}
417418

418419
private onFileSystemChanged(uri: Uri) {
419-
// Ignore .git changes
420-
if (/\.git(?:\/|\\|$)/.test(uri.fsPath)) return;
420+
// Ignore node_modules and .git changes
421+
if (/(?:(?:\/|\\)node_modules|\.git)(?:\/|\\|$)/.test(uri.fsPath)) return;
421422

422423
this._etagFileSystem = Date.now();
423424
this.fireFileSystemChange(uri);
@@ -966,12 +967,18 @@ export class Repository implements Disposable {
966967

967968
this._fireFileSystemChangeDebounced ??= debounce(this.fireFileSystemChangeCore.bind(this), this._fsChangeDelay);
968969

969-
this._pendingFileSystemChange ??= { repository: this, uris: [] };
970+
this._pendingFileSystemChange ??= { repository: this, uris: new UriSet() };
970971
const e = this._pendingFileSystemChange;
971-
e.uris.push(uri);
972+
e.uris.add(uri);
972973

973974
if (this._suspended) {
974-
Logger.debug(scope, `queueing suspended fs changes=${e.uris.map(u => u.fsPath).join(', ')}`);
975+
Logger.debug(
976+
scope,
977+
`queueing suspended fs changes=${join(
978+
map(e.uris, u => u.fsPath),
979+
', ',
980+
)}`,
981+
);
975982
return;
976983
}
977984

@@ -984,15 +991,21 @@ export class Repository implements Disposable {
984991

985992
this._pendingFileSystemChange = undefined;
986993

987-
const uris = await this.git.excludeIgnoredUris(e.uris);
988-
if (uris.length === 0) return;
994+
const uris = await this.git.excludeIgnoredUris([...e.uris]);
995+
if (!uris.length) return;
989996

990-
if (uris.length !== e.uris.length) {
991-
e = { ...e, uris: uris };
997+
if (uris.length !== e.uris.size) {
998+
e = { ...e, uris: new UriSet(uris) };
992999
}
9931000

9941001
using scope = startLogScope(`${getLoggableName(this)}.fireChangeCore`, false);
995-
Logger.debug(scope, `firing fs changes=${e.uris.map(u => u.fsPath).join(', ')}`);
1002+
Logger.debug(
1003+
scope,
1004+
`firing fs changes=${join(
1005+
map(e.uris, u => u.fsPath),
1006+
', ',
1007+
)}`,
1008+
);
9961009

9971010
this._onDidChangeFileSystem.fire(e);
9981011
}

src/system/iterable.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ export function* skip<T>(source: Iterable<T> | IterableIterator<T>, count: numbe
315315
}
316316
}
317317

318+
export function slice<T>(source: Iterable<T> | IterableIterator<T>, start: number, end: number): Iterable<T> {
319+
return skip(take(source, end), start);
320+
}
321+
318322
export function some<T>(source: Iterable<T> | IterableIterator<T>, predicate?: (item: T) => boolean): boolean {
319323
for (const item of source) {
320324
if (predicate == null || predicate(item)) return true;

src/views/nodes/fileHistoryNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { gate } from '../../system/decorators/-webview/gate';
1111
import { memoize } from '../../system/decorators/-webview/memoize';
1212
import { debug } from '../../system/decorators/log';
1313
import { weakEvent } from '../../system/event';
14-
import { filterMap, flatMap, map, uniqueBy } from '../../system/iterable';
14+
import { filterMap, flatMap, map, some, uniqueBy } from '../../system/iterable';
1515
import { getLoggableName, Logger } from '../../system/logger';
1616
import { startLogScope } from '../../system/logger.scope';
1717
import { basename } from '../../system/path';
@@ -226,8 +226,8 @@ export class FileHistoryNode
226226

227227
private onFileSystemChanged(e: RepositoryFileSystemChangeEvent) {
228228
if (this.folder) {
229-
if (!e.uris.some(uri => uri.fsPath.startsWith(this.uri.fsPath))) return;
230-
} else if (!e.uris.some(uri => uri.toString() === this.uri.toString())) {
229+
if (!some(e.uris, uri => uri.fsPath.startsWith(this.uri.fsPath))) return;
230+
} else if (!e.uris.has(this.uri)) {
231231
return;
232232
}
233233

src/views/nodes/lineHistoryNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class LineHistoryNode
228228
}
229229

230230
private onFileSystemChanged(e: RepositoryFileSystemChangeEvent) {
231-
if (!e.uris.some(uri => uri.toString() === this.uri.toString())) return;
231+
if (!e.uris.has(this.uri)) return;
232232

233233
using scope = startLogScope(
234234
`${getLoggableName(this)}.onFileSystemChanged(e=${this.uri.toString(true)})`,

src/views/nodes/repositoryNode.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { gate } from '../../system/decorators/-webview/gate';
1616
import { debug, log } from '../../system/decorators/log';
1717
import { weakEvent } from '../../system/event';
1818
import { disposableInterval } from '../../system/function';
19+
import { join, map, slice } from '../../system/iterable';
1920
import { pad } from '../../system/string';
2021
import type { ViewsWithRepositories } from '../viewBase';
2122
import { createViewDecorationUri } from '../viewDecorationProvider';
@@ -393,10 +394,10 @@ export class RepositoryNode extends SubscribeableViewNode<'repository', ViewsWit
393394
@debug<RepositoryNode['onFileSystemChanged']>({
394395
args: {
395396
0: e =>
396-
`{ repository: ${e.repository.name ?? ''}, uris(${e.uris.length}): [${e.uris
397-
.slice(0, 1)
398-
.map(u => u.fsPath)
399-
.join(', ')}${e.uris.length > 1 ? ', ...' : ''}] }`,
397+
`{ repository: ${e.repository.name ?? ''}, uris(${e.uris.size}): [${join(
398+
map(slice(e.uris, 0, 1), u => u.fsPath),
399+
', ',
400+
)}${e.uris.size > 1 ? ', ...' : ''}] }`,
400401
},
401402
})
402403
private async onFileSystemChanged(_e: RepositoryFileSystemChangeEvent) {

0 commit comments

Comments
 (0)