提交 bdc326b9 编写于 作者: S Sandeep Somavarapu

Fix #25780:

Remove ArraySet and move to native Set
上级 1cc8f3ce
......@@ -3,28 +3,27 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ArraySet } from 'vs/base/common/set';
import { INavigator, ArrayNavigator } from 'vs/base/common/iterator';
export class HistoryNavigator<T> implements INavigator<T> {
private _history: ArraySet<T>;
private _history: Set<T>;
private _limit: number;
private _navigator: ArrayNavigator<T>;
constructor(history: T[] = [], limit: number = 10) {
this._history = new ArraySet(history);
this._initialize(history);
this._limit = limit;
this._onChange();
}
public add(t: T) {
this._history.set(t);
this._history.add(t);
this._onChange();
}
public addIfNotPresent(t: T) {
if (!this._history.contains(t)) {
if (!this._history.has(t)) {
this.add(t);
}
}
......@@ -63,15 +62,27 @@ export class HistoryNavigator<T> implements INavigator<T> {
private _onChange() {
this._reduceToLimit();
this._navigator = new ArrayNavigator(this._history.elements);
this._navigator = new ArrayNavigator(this._elements);
this._navigator.last();
}
private _reduceToLimit() {
let data = this._history.elements;
let data = this._elements;
if (data.length > this._limit) {
this._history = new ArraySet<T>(data.slice(data.length - this._limit));
this._initialize(data.slice(data.length - this._limit));
}
}
private _initialize(history: T[]): void {
this._history = new Set();
for (const entry of history) {
this._history.add(entry);
}
}
private get _elements(): T[] {
const elements: T[] = [];
this._history.forEach(e => elements.push(e));
return elements;
}
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export class ArraySet<T> {
private _elements: T[];
constructor(elements: T[] = []) {
this._elements = elements.slice();
}
get size(): number {
return this._elements.length;
}
set(element: T): void {
this.unset(element);
this._elements.push(element);
}
contains(element: T): boolean {
return this._elements.indexOf(element) > -1;
}
unset(element: T): void {
const index = this._elements.indexOf(element);
if (index > -1) {
this._elements.splice(index, 1);
}
}
get elements(): T[] {
return this._elements.slice();
}
}
\ No newline at end of file
......@@ -6,7 +6,6 @@
import 'vs/css!./media/markers';
import * as errors from 'vs/base/common/errors';
import * as Set from 'vs/base/common/set';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { Delayer } from 'vs/base/common/async';
......@@ -53,7 +52,7 @@ export class MarkersPanel extends Panel {
private hasToAutoReveal: boolean;
private tree: Tree.ITree;
private autoExpanded: Set.ArraySet<string>;
private autoExpanded: Set<string>;
private rangeHighlightDecorations: RangeHighlightDecorations;
private actions: IAction[];
......@@ -81,7 +80,7 @@ export class MarkersPanel extends Panel {
super(Constants.MARKERS_PANEL_ID, telemetryService, themeService);
this.toDispose = [];
this.delayedRefresh = new Delayer<void>(500);
this.autoExpanded = new Set.ArraySet<string>();
this.autoExpanded = new Set<string>();
this.markerFocusContextKey = Constants.MarkerFocusContextKey.bindTo(contextKeyService);
}
......@@ -188,7 +187,7 @@ export class MarkersPanel extends Panel {
public updateFilter(filter: string) {
this.markersModel.update(new FilterOptions(filter));
this.autoExpanded = new Set.ArraySet<string>();
this.autoExpanded = new Set<string>();
this.refreshPanel();
this.autoReveal();
}
......@@ -304,7 +303,7 @@ export class MarkersPanel extends Panel {
bulkUpdater.done();
for (const resource of resources) {
if (!this.markersModel.hasResource(resource)) {
this.autoExpanded.unset(resource.toString());
this.autoExpanded.delete(resource.toString());
}
}
}
......@@ -326,9 +325,9 @@ export class MarkersPanel extends Panel {
private autoExpand(): void {
for (const resource of this.markersModel.filteredResources) {
const resourceUri = resource.uri.toString();
if (!this.autoExpanded.contains(resourceUri)) {
if (!this.autoExpanded.has(resourceUri)) {
this.tree.expand(resource).done(null, errors.onUnexpectedError);
this.autoExpanded.set(resourceUri);
this.autoExpanded.add(resourceUri);
}
}
}
......
......@@ -12,7 +12,6 @@ import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { TPromise, PPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import { SimpleMap } from 'vs/base/common/map';
import { ArraySet } from 'vs/base/common/set';
import Event, { Emitter, fromPromise, stopwatch, any } from 'vs/base/common/event';
import { ISearchService, ISearchProgressItem, ISearchComplete, ISearchQuery, IPatternInfo, IFileMatch } from 'vs/platform/search/common/search';
import { ReplacePattern } from 'vs/platform/search/common/replace';
......@@ -127,7 +126,7 @@ export class FileMatch extends Disposable {
private _model: IModel;
private _modelListener: IDisposable;
private _matches: SimpleMap<string, Match>;
private _removedMatches: ArraySet<string>;
private _removedMatches: Set<string>;
private _selectedMatch: Match;
private _updateScheduler: RunOnceScheduler;
......@@ -138,7 +137,7 @@ export class FileMatch extends Disposable {
super();
this._resource = this.rawMatch.resource;
this._matches = new SimpleMap<string, Match>();
this._removedMatches = new ArraySet<string>();
this._removedMatches = new Set<string>();
this._updateScheduler = new RunOnceScheduler(this.updateMatchesForModel.bind(this), 250);
this.createMatches();
......@@ -222,7 +221,7 @@ export class FileMatch extends Disposable {
private updateMatches(matches: FindMatch[], modelChange: boolean) {
matches.forEach(m => {
let match = new Match(this, this._model.getLineContent(m.range.startLineNumber), m.range.startLineNumber - 1, m.range.startColumn - 1, m.range.endColumn - m.range.startColumn);
if (!this._removedMatches.contains(match.id())) {
if (!this._removedMatches.has(match.id())) {
this.add(match);
if (this.isMatchSelected(match)) {
this._selectedMatch = match;
......@@ -263,7 +262,7 @@ export class FileMatch extends Disposable {
public remove(match: Match): void {
this.removeMatch(match);
this._removedMatches.set(match.id());
this._removedMatches.add(match.id());
this._onChange.fire(false);
}
......
......@@ -8,7 +8,6 @@
import winjs = require('vs/base/common/winjs.base');
import errors = require('vs/base/common/errors');
import URI from 'vs/base/common/uri';
import { ArraySet } from 'vs/base/common/set';
import { IFileService } from 'vs/platform/files/common/files';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
......@@ -60,12 +59,12 @@ function extractDomain(url: string): string {
}
export function getDomainsOfRemotes(text: string, whitelist: string[]): string[] {
let domains = new ArraySet<string>();
let domains = new Set<string>();
let match: RegExpExecArray;
while (match = RemoteMatcher.exec(text)) {
let domain = extractDomain(match[1]);
if (domain) {
domains.set(domain);
domains.add(domain);
}
}
......@@ -74,7 +73,10 @@ export function getDomainsOfRemotes(text: string, whitelist: string[]): string[]
return map;
}, Object.create(null));
return domains.elements
const elements: string[] = [];
domains.forEach(e => elements.push(e));
return elements
.map(key => whitemap[key] ? key : key.replace(AnyButDot, 'a'));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册