Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
100c0273
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
100c0273
编写于
8月 27, 2021
作者:
H
Henning Dieterichs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improves performance of concat23Trees
上级
02e94bc1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
40 deletion
+49
-40
src/vs/editor/common/model/bracketPairColorizer/ast.ts
src/vs/editor/common/model/bracketPairColorizer/ast.ts
+1
-1
src/vs/editor/common/model/bracketPairColorizer/concat23Trees.ts
...editor/common/model/bracketPairColorizer/concat23Trees.ts
+45
-37
src/vs/editor/common/model/bracketPairColorizer/parser.ts
src/vs/editor/common/model/bracketPairColorizer/parser.ts
+3
-2
未找到文件。
src/vs/editor/common/model/bracketPairColorizer/ast.ts
浏览文件 @
100c0273
...
...
@@ -163,7 +163,7 @@ function computeLength(openingBracket: BracketAstNode, child: AstNode | null, cl
}
export
class
ListAstNode
extends
BaseAstNode
{
public
static
create
(
items
:
AstNode
[])
{
public
static
create
(
items
:
AstNode
[])
:
ListAstNode
{
if
(
items
.
length
===
0
)
{
return
new
ListAstNode
(
lengthZero
,
0
,
items
,
SmallImmutableSet
.
getEmpty
());
}
else
{
...
...
src/vs/editor/common/model/bracketPairColorizer/concat23Trees.ts
浏览文件 @
100c0273
...
...
@@ -19,30 +19,59 @@ export function concat23Trees(items: AstNode[]): AstNode | null {
return
items
[
0
];
}
if
(
allItemsHaveSameHeight
(
items
))
{
return
concatFast
(
items
);
let
i
=
0
;
function
readNode
():
AstNode
|
null
{
if
(
i
>=
items
.
length
)
{
return
null
;
}
const
start
=
i
;
const
height
=
items
[
start
].
listHeight
;
i
++
;
while
(
i
<
items
.
length
&&
items
[
i
].
listHeight
===
height
)
{
i
++
;
}
if
(
i
-
start
>=
2
)
{
return
concat23TreesOfSameHeight
(
start
===
0
&&
i
===
items
.
length
?
items
:
items
.
slice
(
start
,
i
));
}
else
{
return
items
[
start
];
}
}
return
concatSlow
(
items
);
}
/**
* @param items must be non empty.
*/
function
allItemsHaveSameHeight
(
items
:
AstNode
[]):
boolean
{
const
firstHeight
=
items
[
0
].
listHeight
;
// The items might not have the same height.
// We merge all items by using a binary concat operator.
let
first
=
readNode
()
!
;
// There must be a first item
let
second
=
readNode
();
if
(
!
second
)
{
return
first
;
}
for
(
const
item
of
items
)
{
if
(
item
.
listHeight
!==
firstHeight
)
{
return
false
;
for
(
let
item
=
readNode
();
item
;
item
=
readNode
())
{
// Prefer concatenating smaller trees, as the runtime of concat depends on the tree height.
if
(
heightDiff
(
first
,
second
)
<=
heightDiff
(
second
,
item
))
{
first
=
concat
(
first
,
second
);
second
=
item
;
}
else
{
second
=
concat
(
second
,
item
);
}
}
return
true
;
const
result
=
concat
(
first
,
second
);
return
result
;
}
function
concatFast
(
items
:
AstNode
[]):
AstNode
|
null
{
export
function
concat23TreesOfSameHeight
(
items
:
AstNode
[]):
AstNode
|
null
{
if
(
items
.
length
===
0
)
{
return
null
;
}
if
(
items
.
length
===
1
)
{
return
items
[
0
];
}
let
length
=
items
.
length
;
// All trees have same height, just create parent nodes.
while
(
length
>
1
)
{
while
(
length
>
3
)
{
const
newLength
=
length
>>
1
;
// Ideally, due to the slice, not a lot of memory is wasted.
const
newItems
=
new
Array
<
AstNode
>
(
newLength
);
...
...
@@ -53,34 +82,13 @@ function concatFast(items: AstNode[]): AstNode | null {
length
=
newLength
;
items
=
newItems
;
}
return
items
[
0
]
;
return
ListAstNode
.
create
(
items
)
;
}
function
heightDiff
(
node1
:
AstNode
,
node2
:
AstNode
):
number
{
return
Math
.
abs
(
node1
.
listHeight
-
node2
.
listHeight
);
}
function
concatSlow
(
items
:
AstNode
[]):
AstNode
|
null
{
// The items might not have the same height.
// We merge all items by using a binary concat operator.
let
first
=
items
[
0
];
let
second
=
items
[
1
];
for
(
let
i
=
2
;
i
<
items
.
length
;
i
++
)
{
const
item
=
items
[
i
];
// Prefer concatenating smaller trees, as the runtime of concat depends on the tree height.
if
(
heightDiff
(
first
,
second
)
<=
heightDiff
(
second
,
item
))
{
first
=
concat
(
first
,
second
);
second
=
item
;
}
else
{
second
=
concat
(
second
,
item
);
}
}
const
result
=
concat
(
first
,
second
);
return
result
;
}
function
concat
(
node1
:
AstNode
,
node2
:
AstNode
):
AstNode
{
if
(
node1
.
listHeight
===
node2
.
listHeight
)
{
return
ListAstNode
.
create
([
node1
,
node2
]);
...
...
src/vs/editor/common/model/bracketPairColorizer/parser.ts
浏览文件 @
100c0273
...
...
@@ -7,7 +7,7 @@ import { AstNode, AstNodeKind, BracketAstNode, InvalidBracketAstNode, ListAstNod
import
{
BeforeEditPositionMapper
,
TextEditInfo
}
from
'
./beforeEditPositionMapper
'
;
import
{
SmallImmutableSet
}
from
'
./smallImmutableSet
'
;
import
{
lengthGetLineCount
,
lengthIsZero
,
lengthLessThanEqual
}
from
'
./length
'
;
import
{
concat23Trees
}
from
'
./concat23Trees
'
;
import
{
concat23Trees
,
concat23TreesOfSameHeight
}
from
'
./concat23Trees
'
;
import
{
NodeReader
}
from
'
./nodeReader
'
;
import
{
OpeningBracketId
,
Tokenizer
,
TokenKind
}
from
'
./tokenizer
'
;
...
...
@@ -80,7 +80,8 @@ class Parser {
items
.
push
(
child
);
}
const
result
=
concat23Trees
(
items
);
// When there is no oldNodeReader, all items are created from scratch and must have the same height.
const
result
=
this
.
oldNodeReader
?
concat23Trees
(
items
)
:
concat23TreesOfSameHeight
(
items
);
return
result
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录