Add arrays.empty

This helps with `a === b` checks  in arrays.equals
This commit is contained in:
Matt Bierner
2019-05-30 17:22:38 -07:00
parent 015f1c7909
commit 76e774e4bd
2 changed files with 5 additions and 3 deletions

View File

@@ -18,12 +18,12 @@ function diagnosticsEquals(a: vscode.Diagnostic, b: vscode.Diagnostic): boolean
&& a.severity === b.severity
&& a.source === b.source
&& a.range.isEqual(b.range)
&& arrays.equals(a.relatedInformation || [], b.relatedInformation || [], (a, b) => {
&& arrays.equals(a.relatedInformation || arrays.empty, b.relatedInformation || arrays.empty, (a, b) => {
return a.message === b.message
&& a.location.range.isEqual(b.location.range)
&& a.location.uri.fsPath === b.location.uri.fsPath;
})
&& arrays.equals(a.tags || [], b.tags || []);
&& arrays.equals(a.tags || arrays.empty, b.tags || arrays.empty);
}
export const enum DiagnosticKind {
@@ -51,7 +51,7 @@ class FileDiagnostics {
}
const existing = this._diagnostics.get(kind);
if (arrays.equals(existing || [], diagnostics, diagnosticsEquals)) {
if (arrays.equals(existing || arrays.empty, diagnostics, diagnosticsEquals)) {
// No need to update
return false;
}

View File

@@ -3,6 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export const empty = Object.freeze([]);
export function equals<T>(
a: ReadonlyArray<T>,
b: ReadonlyArray<T>,