Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
fb196011
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fb196011
编写于
5月 05, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt/es6 - make LinkedMap a ES6 map
fyi @dbaeumer
上级
bf77670c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
70 addition
and
63 deletion
+70
-63
src/vs/base/common/map.ts
src/vs/base/common/map.ts
+34
-29
src/vs/base/test/common/map.test.ts
src/vs/base/test/common/map.test.ts
+31
-29
src/vs/workbench/browser/parts/editor/editorsObserver.ts
src/vs/workbench/browser/parts/editor/editorsObserver.ts
+3
-3
src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
...vs/workbench/contrib/tasks/browser/abstractTaskService.ts
+2
-2
未找到文件。
src/vs/base/common/map.ts
浏览文件 @
fb196011
...
...
@@ -580,7 +580,9 @@ export const enum Touch {
AsNew
=
2
}
export
class
LinkedMap
<
K
,
V
>
{
export
class
LinkedMap
<
K
,
V
>
implements
Map
<
K
,
V
>
{
readonly
[
Symbol
.
toStringTag
]
=
'
LinkedMap
'
;
private
_map
:
Map
<
K
,
Item
<
K
,
V
>>
;
private
_head
:
Item
<
K
,
V
>
|
undefined
;
...
...
@@ -632,7 +634,7 @@ export class LinkedMap<K, V> {
return
item
.
value
;
}
set
(
key
:
K
,
value
:
V
,
touch
:
Touch
=
Touch
.
None
):
void
{
set
(
key
:
K
,
value
:
V
,
touch
:
Touch
=
Touch
.
None
):
this
{
let
item
=
this
.
_map
.
get
(
key
);
if
(
item
)
{
item
.
value
=
value
;
...
...
@@ -658,6 +660,7 @@ export class LinkedMap<K, V> {
this
.
_map
.
set
(
key
,
item
);
this
.
_size
++
;
}
return
this
;
}
delete
(
key
:
K
):
boolean
{
...
...
@@ -701,34 +704,13 @@ export class LinkedMap<K, V> {
}
}
values
():
V
[]
{
const
result
:
V
[]
=
[];
let
current
=
this
.
_head
;
while
(
current
)
{
result
.
push
(
current
.
value
);
current
=
current
.
next
;
}
return
result
;
}
keys
():
K
[]
{
const
result
:
K
[]
=
[];
let
current
=
this
.
_head
;
while
(
current
)
{
result
.
push
(
current
.
key
);
current
=
current
.
next
;
}
return
result
;
}
/* VS Code / Monaco editor runs on es5 which has no Symbol.iterator
keys
():
IterableIterator
<
K
>
{
cons
t current = this._head;
le
t
current
=
this
.
_head
;
const
iterator
:
IterableIterator
<
K
>
=
{
[
Symbol
.
iterator
]()
{
return
iterator
;
},
next():IteratorResult<K> {
next
():
IteratorResult
<
K
>
{
if
(
current
)
{
const
result
=
{
value
:
current
.
key
,
done
:
false
};
current
=
current
.
next
;
...
...
@@ -742,12 +724,12 @@ export class LinkedMap<K, V> {
}
values
():
IterableIterator
<
V
>
{
cons
t current = this._head;
le
t
current
=
this
.
_head
;
const
iterator
:
IterableIterator
<
V
>
=
{
[
Symbol
.
iterator
]()
{
return
iterator
;
},
next():IteratorResult<V> {
next
():
IteratorResult
<
V
>
{
if
(
current
)
{
const
result
=
{
value
:
current
.
value
,
done
:
false
};
current
=
current
.
next
;
...
...
@@ -759,7 +741,29 @@ export class LinkedMap<K, V> {
};
return
iterator
;
}
*/
entries
():
IterableIterator
<
[
K
,
V
]
>
{
let
current
=
this
.
_head
;
const
iterator
:
IterableIterator
<
[
K
,
V
]
>
=
{
[
Symbol
.
iterator
]()
{
return
iterator
;
},
next
():
IteratorResult
<
[
K
,
V
]
>
{
if
(
current
)
{
const
result
:
IteratorResult
<
[
K
,
V
]
>
=
{
value
:
[
current
.
key
,
current
.
value
],
done
:
false
};
current
=
current
.
next
;
return
result
;
}
else
{
return
{
value
:
undefined
,
done
:
true
};
}
}
};
return
iterator
;
}
[
Symbol
.
iterator
]():
IterableIterator
<
[
K
,
V
]
>
{
return
this
.
entries
();
}
protected
trimOld
(
newSize
:
number
)
{
if
(
newSize
>=
this
.
size
)
{
...
...
@@ -961,9 +965,10 @@ export class LRUCache<K, V> extends LinkedMap<K, V> {
return
super
.
get
(
key
,
Touch
.
None
);
}
set
(
key
:
K
,
value
:
V
):
void
{
set
(
key
:
K
,
value
:
V
):
this
{
super
.
set
(
key
,
value
,
Touch
.
AsNew
);
this
.
checkTrim
();
return
this
;
}
private
checkTrim
()
{
...
...
src/vs/base/test/common/map.test.ts
浏览文件 @
fb196011
...
...
@@ -13,8 +13,8 @@ suite('Map', () => {
let
map
=
new
LinkedMap
<
string
,
string
>
();
map
.
set
(
'
ak
'
,
'
av
'
);
map
.
set
(
'
bk
'
,
'
bv
'
);
assert
.
deepStrictEqual
(
map
.
keys
()
,
[
'
ak
'
,
'
bk
'
]);
assert
.
deepStrictEqual
(
map
.
values
()
,
[
'
av
'
,
'
bv
'
]);
assert
.
deepStrictEqual
(
[...
map
.
keys
()]
,
[
'
ak
'
,
'
bk
'
]);
assert
.
deepStrictEqual
(
[...
map
.
values
()]
,
[
'
av
'
,
'
bv
'
]);
assert
.
equal
(
map
.
first
,
'
av
'
);
assert
.
equal
(
map
.
last
,
'
bv
'
);
});
...
...
@@ -23,16 +23,16 @@ suite('Map', () => {
let
map
=
new
LinkedMap
<
string
,
string
>
();
map
.
set
(
'
ak
'
,
'
av
'
);
map
.
set
(
'
ak
'
,
'
av
'
,
Touch
.
AsOld
);
assert
.
deepStrictEqual
(
map
.
keys
()
,
[
'
ak
'
]);
assert
.
deepStrictEqual
(
map
.
values
()
,
[
'
av
'
]);
assert
.
deepStrictEqual
(
[...
map
.
keys
()]
,
[
'
ak
'
]);
assert
.
deepStrictEqual
(
[...
map
.
values
()]
,
[
'
av
'
]);
});
test
(
'
LinkedMap - Touch New one
'
,
()
=>
{
let
map
=
new
LinkedMap
<
string
,
string
>
();
map
.
set
(
'
ak
'
,
'
av
'
);
map
.
set
(
'
ak
'
,
'
av
'
,
Touch
.
AsNew
);
assert
.
deepStrictEqual
(
map
.
keys
()
,
[
'
ak
'
]);
assert
.
deepStrictEqual
(
map
.
values
()
,
[
'
av
'
]);
assert
.
deepStrictEqual
(
[...
map
.
keys
()]
,
[
'
ak
'
]);
assert
.
deepStrictEqual
(
[...
map
.
values
()]
,
[
'
av
'
]);
});
test
(
'
LinkedMap - Touch Old two
'
,
()
=>
{
...
...
@@ -40,8 +40,8 @@ suite('Map', () => {
map
.
set
(
'
ak
'
,
'
av
'
);
map
.
set
(
'
bk
'
,
'
bv
'
);
map
.
set
(
'
bk
'
,
'
bv
'
,
Touch
.
AsOld
);
assert
.
deepStrictEqual
(
map
.
keys
()
,
[
'
bk
'
,
'
ak
'
]);
assert
.
deepStrictEqual
(
map
.
values
()
,
[
'
bv
'
,
'
av
'
]);
assert
.
deepStrictEqual
(
[...
map
.
keys
()]
,
[
'
bk
'
,
'
ak
'
]);
assert
.
deepStrictEqual
(
[...
map
.
values
()]
,
[
'
bv
'
,
'
av
'
]);
});
test
(
'
LinkedMap - Touch New two
'
,
()
=>
{
...
...
@@ -49,8 +49,8 @@ suite('Map', () => {
map
.
set
(
'
ak
'
,
'
av
'
);
map
.
set
(
'
bk
'
,
'
bv
'
);
map
.
set
(
'
ak
'
,
'
av
'
,
Touch
.
AsNew
);
assert
.
deepStrictEqual
(
map
.
keys
()
,
[
'
bk
'
,
'
ak
'
]);
assert
.
deepStrictEqual
(
map
.
values
()
,
[
'
bv
'
,
'
av
'
]);
assert
.
deepStrictEqual
(
[...
map
.
keys
()]
,
[
'
bk
'
,
'
ak
'
]);
assert
.
deepStrictEqual
(
[...
map
.
values
()]
,
[
'
bv
'
,
'
av
'
]);
});
test
(
'
LinkedMap - Touch Old from middle
'
,
()
=>
{
...
...
@@ -59,8 +59,8 @@ suite('Map', () => {
map
.
set
(
'
bk
'
,
'
bv
'
);
map
.
set
(
'
ck
'
,
'
cv
'
);
map
.
set
(
'
bk
'
,
'
bv
'
,
Touch
.
AsOld
);
assert
.
deepStrictEqual
(
map
.
keys
()
,
[
'
bk
'
,
'
ak
'
,
'
ck
'
]);
assert
.
deepStrictEqual
(
map
.
values
()
,
[
'
bv
'
,
'
av
'
,
'
cv
'
]);
assert
.
deepStrictEqual
(
[...
map
.
keys
()]
,
[
'
bk
'
,
'
ak
'
,
'
ck
'
]);
assert
.
deepStrictEqual
(
[...
map
.
values
()]
,
[
'
bv
'
,
'
av
'
,
'
cv
'
]);
});
test
(
'
LinkedMap - Touch New from middle
'
,
()
=>
{
...
...
@@ -69,8 +69,8 @@ suite('Map', () => {
map
.
set
(
'
bk
'
,
'
bv
'
);
map
.
set
(
'
ck
'
,
'
cv
'
);
map
.
set
(
'
bk
'
,
'
bv
'
,
Touch
.
AsNew
);
assert
.
deepStrictEqual
(
map
.
keys
()
,
[
'
ak
'
,
'
ck
'
,
'
bk
'
]);
assert
.
deepStrictEqual
(
map
.
values
()
,
[
'
av
'
,
'
cv
'
,
'
bv
'
]);
assert
.
deepStrictEqual
(
[...
map
.
keys
()]
,
[
'
ak
'
,
'
ck
'
,
'
bk
'
]);
assert
.
deepStrictEqual
(
[...
map
.
values
()]
,
[
'
av
'
,
'
cv
'
,
'
bv
'
]);
});
test
(
'
LinkedMap - basics
'
,
function
()
{
...
...
@@ -136,13 +136,15 @@ suite('Map', () => {
assert
.
strictEqual
(
cache
.
size
,
5
);
cache
.
set
(
6
,
6
);
assert
.
strictEqual
(
cache
.
size
,
5
);
assert
.
deepStrictEqual
(
cache
.
keys
()
,
[
2
,
3
,
4
,
5
,
6
]);
assert
.
deepStrictEqual
(
[...
cache
.
keys
()]
,
[
2
,
3
,
4
,
5
,
6
]);
cache
.
set
(
7
,
7
);
assert
.
strictEqual
(
cache
.
size
,
5
);
assert
.
deepStrictEqual
(
cache
.
keys
()
,
[
3
,
4
,
5
,
6
,
7
]);
assert
.
deepStrictEqual
(
[...
cache
.
keys
()]
,
[
3
,
4
,
5
,
6
,
7
]);
let
values
:
number
[]
=
[];
[
3
,
4
,
5
,
6
,
7
].
forEach
(
key
=>
values
.
push
(
cache
.
get
(
key
)
!
));
assert
.
deepStrictEqual
(
values
,
[
3
,
4
,
5
,
6
,
7
]);
assert
.
deepEqual
([...
cache
.
entries
()],
[[
3
,
3
],
[
4
,
4
],
[
5
,
5
],
[
6
,
6
],
[
7
,
7
]]);
});
test
(
'
LinkedMap - LRU Cache get
'
,
()
=>
{
...
...
@@ -150,11 +152,11 @@ suite('Map', () => {
[
1
,
2
,
3
,
4
,
5
].
forEach
(
value
=>
cache
.
set
(
value
,
value
));
assert
.
strictEqual
(
cache
.
size
,
5
);
assert
.
deepStrictEqual
(
cache
.
keys
()
,
[
1
,
2
,
3
,
4
,
5
]);
assert
.
deepStrictEqual
(
[...
cache
.
keys
()]
,
[
1
,
2
,
3
,
4
,
5
]);
cache
.
get
(
3
);
assert
.
deepStrictEqual
(
cache
.
keys
()
,
[
1
,
2
,
4
,
5
,
3
]);
assert
.
deepStrictEqual
(
[...
cache
.
keys
()]
,
[
1
,
2
,
4
,
5
,
3
]);
cache
.
peek
(
4
);
assert
.
deepStrictEqual
(
cache
.
keys
()
,
[
1
,
2
,
4
,
5
,
3
]);
assert
.
deepStrictEqual
(
[...
cache
.
keys
()]
,
[
1
,
2
,
4
,
5
,
3
]);
let
values
:
number
[]
=
[];
[
1
,
2
,
3
,
4
,
5
].
forEach
(
key
=>
values
.
push
(
cache
.
get
(
key
)
!
));
assert
.
deepStrictEqual
(
values
,
[
1
,
2
,
3
,
4
,
5
]);
...
...
@@ -169,7 +171,7 @@ suite('Map', () => {
assert
.
strictEqual
(
cache
.
size
,
10
);
cache
.
limit
=
5
;
assert
.
strictEqual
(
cache
.
size
,
5
);
assert
.
deepStrictEqual
(
cache
.
keys
()
,
[
6
,
7
,
8
,
9
,
10
]);
assert
.
deepStrictEqual
(
[...
cache
.
keys
()]
,
[
6
,
7
,
8
,
9
,
10
]);
cache
.
limit
=
20
;
assert
.
strictEqual
(
cache
.
size
,
5
);
for
(
let
i
=
11
;
i
<=
20
;
i
++
)
{
...
...
@@ -181,7 +183,7 @@ suite('Map', () => {
values
.
push
(
cache
.
get
(
i
)
!
);
assert
.
strictEqual
(
cache
.
get
(
i
),
i
);
}
assert
.
deepStrictEqual
(
cache
.
values
()
,
values
);
assert
.
deepStrictEqual
(
[...
cache
.
values
()]
,
values
);
});
test
(
'
LinkedMap - LRU Cache limit with ratio
'
,
()
=>
{
...
...
@@ -193,11 +195,11 @@ suite('Map', () => {
assert
.
strictEqual
(
cache
.
size
,
10
);
cache
.
set
(
11
,
11
);
assert
.
strictEqual
(
cache
.
size
,
5
);
assert
.
deepStrictEqual
(
cache
.
keys
()
,
[
7
,
8
,
9
,
10
,
11
]);
assert
.
deepStrictEqual
(
[...
cache
.
keys
()]
,
[
7
,
8
,
9
,
10
,
11
]);
let
values
:
number
[]
=
[];
cache
.
keys
()
.
forEach
(
key
=>
values
.
push
(
cache
.
get
(
key
)
!
));
[...
cache
.
keys
()]
.
forEach
(
key
=>
values
.
push
(
cache
.
get
(
key
)
!
));
assert
.
deepStrictEqual
(
values
,
[
7
,
8
,
9
,
10
,
11
]);
assert
.
deepStrictEqual
(
cache
.
values
()
,
values
);
assert
.
deepStrictEqual
(
[...
cache
.
values
()]
,
values
);
});
test
(
'
LinkedMap - toJSON / fromJSON
'
,
()
=>
{
...
...
@@ -237,7 +239,7 @@ suite('Map', () => {
map
.
delete
(
'
1
'
);
assert
.
equal
(
map
.
get
(
'
1
'
),
undefined
);
assert
.
equal
(
map
.
size
,
0
);
assert
.
equal
(
map
.
keys
()
.
length
,
0
);
assert
.
equal
(
[...
map
.
keys
()]
.
length
,
0
);
});
test
(
'
LinkedMap - delete Head
'
,
function
()
{
...
...
@@ -251,8 +253,8 @@ suite('Map', () => {
map
.
delete
(
'
1
'
);
assert
.
equal
(
map
.
get
(
'
2
'
),
2
);
assert
.
equal
(
map
.
size
,
1
);
assert
.
equal
(
map
.
keys
()
.
length
,
1
);
assert
.
equal
(
map
.
keys
()
[
0
],
2
);
assert
.
equal
(
[...
map
.
keys
()]
.
length
,
1
);
assert
.
equal
(
[...
map
.
keys
()]
[
0
],
2
);
});
test
(
'
LinkedMap - delete Tail
'
,
function
()
{
...
...
@@ -266,8 +268,8 @@ suite('Map', () => {
map
.
delete
(
'
2
'
);
assert
.
equal
(
map
.
get
(
'
1
'
),
1
);
assert
.
equal
(
map
.
size
,
1
);
assert
.
equal
(
map
.
keys
()
.
length
,
1
);
assert
.
equal
(
map
.
keys
()
[
0
],
1
);
assert
.
equal
(
[...
map
.
keys
()]
.
length
,
1
);
assert
.
equal
(
[...
map
.
keys
()]
[
0
],
1
);
});
...
...
src/vs/workbench/browser/parts/editor/editorsObserver.ts
浏览文件 @
fb196011
...
...
@@ -48,7 +48,7 @@ export class EditorsObserver extends Disposable {
}
get
editors
():
IEditorIdentifier
[]
{
return
this
.
mostRecentEditorsMap
.
values
()
;
return
[...
this
.
mostRecentEditorsMap
.
values
()]
;
}
hasEditor
(
resource
:
URI
):
boolean
{
...
...
@@ -283,7 +283,7 @@ export class EditorsObserver extends Disposable {
// Across all editor groups
else
{
await
this
.
doEnsureOpenedEditorsLimit
(
limit
,
this
.
mostRecentEditorsMap
.
values
()
,
exclude
);
await
this
.
doEnsureOpenedEditorsLimit
(
limit
,
[...
this
.
mostRecentEditorsMap
.
values
()]
,
exclude
);
}
}
...
...
@@ -342,7 +342,7 @@ export class EditorsObserver extends Disposable {
private
serialize
():
ISerializedEditorsList
{
const
registry
=
Registry
.
as
<
IEditorInputFactoryRegistry
>
(
Extensions
.
EditorInputFactories
);
const
entries
=
this
.
mostRecentEditorsMap
.
values
()
;
const
entries
=
[...
this
.
mostRecentEditorsMap
.
values
()]
;
const
mapGroupToSerializableEditorsOfGroup
=
new
Map
<
IEditorGroup
,
IEditorInput
[]
>
();
return
{
...
...
src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
浏览文件 @
fb196011
...
...
@@ -791,7 +791,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
if
(
quickOpenHistoryLimit
===
0
)
{
return
;
}
let
keys
=
this
.
_recentlyUsedTasks
.
keys
()
;
let
keys
=
[...
this
.
_recentlyUsedTasks
.
keys
()]
;
if
(
keys
.
length
>
quickOpenHistoryLimit
)
{
keys
=
keys
.
slice
(
0
,
quickOpenHistoryLimit
);
}
...
...
@@ -2323,7 +2323,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
taskMap
[
key
]
=
task
;
}
});
const
reversed
=
recentlyUsedTasks
.
keys
()
.
reverse
();
const
reversed
=
[...
recentlyUsedTasks
.
keys
()]
.
reverse
();
for
(
const
key
in
reversed
)
{
let
task
=
taskMap
[
key
];
if
(
task
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录