Skip to content

Commit

Permalink
Merge pull request #134280 from microsoft/joh/fillFileEvents
Browse files Browse the repository at this point in the history
add better fill-method (for tuples) and adopt for file events
  • Loading branch information
jrieken committed Oct 4, 2021
2 parents a4342f3 + 41be57c commit 3176fb8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
26 changes: 21 additions & 5 deletions src/vs/base/common/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,27 @@ export class TernarySearchTree<K, V> {
return oldElement;
}

fill(element: V, keys: readonly K[]): void {
const arr = keys.slice(0);
shuffle(arr);
for (let k of arr) {
this.set(k, element);
/**
* Fill the tree with the same value of the given keys
*/
fill(element: V, keys: readonly K[]): void;
/**
* Fill the tree with given [key,value]-tuples
*/
fill(values: readonly [K, V][]): void;
fill(values: readonly [K, V][] | V, keys?: readonly K[]): void {
if (keys) {
const arr = keys.slice(0);
shuffle(arr);
for (let k of arr) {
this.set(k, (<V>values));
}
} else {
const arr = (<[K, V][]>values).slice(0);
shuffle(arr);
for (let entry of arr) {
this.set(entry[0], entry[1]);
}
}
}

Expand Down
32 changes: 19 additions & 13 deletions src/vs/platform/files/common/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,25 +663,31 @@ export class FileChangesEvent {
private readonly deleted: TernarySearchTree<URI, IFileChange> | undefined = undefined;

constructor(changes: readonly IFileChange[], ignorePathCasing: boolean) {

const entriesByType = new Map<FileChangeType, [URI, IFileChange][]>();

for (const change of changes) {
switch (change.type) {
const array = entriesByType.get(change.type);
if (array) {
array.push([change.resource, change]);
} else {
entriesByType.set(change.type, [[change.resource, change]]);
}
}

for (const [key, value] of entriesByType) {
switch (key) {
case FileChangeType.ADDED:
if (!this.added) {
this.added = TernarySearchTree.forUris<IFileChange>(() => ignorePathCasing);
}
this.added.set(change.resource, change);
this.added = TernarySearchTree.forUris<IFileChange>(() => ignorePathCasing);
this.added.fill(value);
break;
case FileChangeType.UPDATED:
if (!this.updated) {
this.updated = TernarySearchTree.forUris<IFileChange>(() => ignorePathCasing);
}
this.updated.set(change.resource, change);
this.updated = TernarySearchTree.forUris<IFileChange>(() => ignorePathCasing);
this.updated.fill(value);
break;
case FileChangeType.DELETED:
if (!this.deleted) {
this.deleted = TernarySearchTree.forUris<IFileChange>(() => ignorePathCasing);
}
this.deleted.set(change.resource, change);
this.deleted = TernarySearchTree.forUris<IFileChange>(() => ignorePathCasing);
this.deleted.fill(value);
break;
}
}
Expand Down

0 comments on commit 3176fb8

Please sign in to comment.