Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
785b4f37
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,发现更多精彩内容 >>
提交
785b4f37
编写于
2月 03, 2016
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
list: improve row cache
上级
0ad0cf0c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
43 deletion
+53
-43
src/vs/base/browser/ui/list/listImpl.ts
src/vs/base/browser/ui/list/listImpl.ts
+21
-13
src/vs/base/browser/ui/list/rowCache.ts
src/vs/base/browser/ui/list/rowCache.ts
+32
-30
未找到文件。
src/vs/base/browser/ui/list/listImpl.ts
浏览文件 @
785b4f37
...
...
@@ -12,17 +12,19 @@ import { IScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableEleme
import
{
ScrollableElement
}
from
'
vs/base/browser/ui/scrollbar/impl/scrollableElement
'
;
import
{
RangeMap
}
from
'
./rangeMap
'
;
import
{
IScrollEvent
,
IDelegate
,
IRendererMap
}
from
'
./list
'
;
import
{
RowCache
}
from
'
./rowCache
'
;
import
{
RowCache
,
IRow
}
from
'
./rowCache
'
;
interface
IItem
{
domNode
:
HTMLElement
;
height
:
number
;
templateId
:
string
;
row
:
IRow
;
}
export
class
List
<
T
>
implements
IScrollable
{
private
items
:
IItem
[];
private
rangeMap
:
RangeMap
;
private
rowC
ache
:
RowCache
<
T
>
;
private
c
ache
:
RowCache
<
T
>
;
private
_scrollTop
:
number
;
private
_viewHeight
:
number
;
...
...
@@ -41,7 +43,7 @@ export class List<T> implements IScrollable {
constructor
(
container
:
HTMLElement
,
delegate
:
IDelegate
<
T
>
,
renderers
:
IRendererMap
<
T
>
)
{
this
.
items
=
[];
this
.
rangeMap
=
new
RangeMap
();
this
.
rowC
ache
=
new
RowCache
(
renderers
);
this
.
c
ache
=
new
RowCache
(
renderers
);
this
.
domNode
=
document
.
createElement
(
'
div
'
);
this
.
domNode
.
className
=
'
monaco-list
'
;
...
...
@@ -176,32 +178,38 @@ export class List<T> implements IScrollable {
private
insertItemInDOM
(
index
:
number
):
void
{
const
item
=
this
.
items
[
index
];
if
(
!
item
.
domNode
)
{
// item.domNode = this.cache.alloc(this.templateId);
item
.
domNode
=
document
.
createElement
(
'
div
'
);
if
(
!
item
.
row
)
{
item
.
row
=
this
.
cache
.
alloc
(
item
.
templateId
);
// used in reverse lookup from HTMLElement to Item
// (<any> this.element)[TreeView.BINDING] = this;
}
if
(
item
.
domNode
.
parentElement
)
{
if
(
item
.
row
.
domNode
.
parentElement
)
{
return
;
}
const
nextItem
=
this
.
items
[
index
+
1
];
if
(
nextItem
&&
nextItem
.
domNode
)
{
this
.
rowsContainer
.
insertBefore
(
item
.
domNode
,
nextItem
.
domNode
);
if
(
nextItem
&&
nextItem
.
row
)
{
this
.
rowsContainer
.
insertBefore
(
item
.
row
.
domNode
,
nextItem
.
row
.
domNode
);
}
else
{
this
.
rowsContainer
.
appendChild
(
item
.
domNode
);
this
.
rowsContainer
.
appendChild
(
item
.
row
.
domNode
);
}
this
.
renderItem
(
index
);
}
private
removeItemFromDOM
(
index
:
number
):
void
{
// TODO
const
item
=
this
.
items
[
index
];
if
(
!
item
.
row
)
{
return
;
}
// (<any> this.element)[TreeView.BINDING] = null;
this
.
cache
.
release
(
item
.
row
);
item
.
row
=
null
;
}
private
renderItem
(
index
:
number
):
void
{
...
...
src/vs/base/browser/ui/list/rowCache.ts
浏览文件 @
785b4f37
...
...
@@ -5,10 +5,10 @@
import
{
IRendererMap
}
from
'
./list
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
DOM
from
'
vs/base/browser/dom
'
;
import
{
append
,
emmet
as
$
,
addClass
,
removeClass
}
from
'
vs/base/browser/dom
'
;
export
interface
IRow
{
element
:
HTMLElement
;
domNode
:
HTMLElement
;
templateId
:
string
;
templateData
:
any
;
}
...
...
@@ -32,72 +32,74 @@ export class RowCache<T> implements IDisposable {
private
scrollingRow
:
IRow
;
constructor
(
private
renderers
:
IRendererMap
<
T
>
)
{
this
.
cache
=
{
''
:
[]
}
;
this
.
cache
=
Object
.
create
(
null
)
;
this
.
scrollingRow
=
null
;
}
public
alloc
(
templateId
:
string
):
IRow
{
/**
* Returns a row either by creating a new one or reusing
* a previously released row which shares the same templateId.
*/
alloc
(
templateId
:
string
):
IRow
{
let
result
=
this
.
getTemplateCache
(
templateId
).
pop
();
if
(
!
result
)
{
const
content
=
document
.
createElement
(
'
div
'
);
content
.
className
=
'
content
'
;
const
row
=
document
.
createElement
(
'
div
'
);
row
.
appendChild
(
content
);
const
domNode
=
$
(
'
div
'
);
const
content
=
append
(
domNode
,
$
(
'
.content
'
));
const
renderer
=
this
.
renderers
[
templateId
];
result
=
{
element
:
row
,
templateId
:
templateId
,
templateData
:
renderer
.
renderTemplate
(
content
)
};
const
templateData
=
renderer
.
renderTemplate
(
content
);
result
=
{
domNode
,
templateId
,
templateData
};
}
return
result
;
}
public
release
(
templateId
:
string
,
row
:
IRow
):
void
{
var
lastScrollTime
=
getLastScrollTime
(
row
.
element
);
/**
* Releases the row for eventual reuse. The row's domNode
* will eventually be removed from its parent, given that
* it is not the currently scrolling row (for OS X ballistic
* scrolling).
*/
release
(
row
:
IRow
):
void
{
var
lastScrollTime
=
getLastScrollTime
(
row
.
domNode
);
if
(
!
lastScrollTime
)
{
removeFromParent
(
row
.
element
);
this
.
getTemplateCache
(
templateId
).
push
(
row
);
removeFromParent
(
row
.
domNode
);
this
.
getTemplateCache
(
row
.
templateId
).
push
(
row
);
return
;
}
if
(
this
.
scrollingRow
)
{
var
lastKnownScrollTime
=
getLastScrollTime
(
this
.
scrollingRow
.
element
);
var
lastKnownScrollTime
=
getLastScrollTime
(
this
.
scrollingRow
.
domNode
);
if
(
lastKnownScrollTime
>
lastScrollTime
)
{
removeFromParent
(
row
.
element
);
this
.
getTemplateCache
(
templateId
).
push
(
row
);
removeFromParent
(
row
.
domNode
);
this
.
getTemplateCache
(
row
.
templateId
).
push
(
row
);
return
;
}
if
(
this
.
scrollingRow
.
element
.
parentElement
)
{
removeFromParent
(
this
.
scrollingRow
.
element
);
DOM
.
removeClass
(
this
.
scrollingRow
.
element
,
'
scrolling
'
);
if
(
this
.
scrollingRow
.
domNode
.
parentElement
)
{
removeFromParent
(
this
.
scrollingRow
.
domNode
);
removeClass
(
this
.
scrollingRow
.
domNode
,
'
scrolling
'
);
this
.
getTemplateCache
(
this
.
scrollingRow
.
templateId
).
push
(
this
.
scrollingRow
);
}
}
this
.
scrollingRow
=
row
;
DOM
.
addClass
(
this
.
scrollingRow
.
element
,
'
scrolling
'
);
addClass
(
this
.
scrollingRow
.
domNode
,
'
scrolling
'
);
}
private
getTemplateCache
(
templateId
:
string
):
IRow
[]
{
return
this
.
cache
[
templateId
]
||
(
this
.
cache
[
templateId
]
=
[]);
}
public
garbageCollect
():
void
{
garbageCollect
():
void
{
if
(
this
.
cache
)
{
Object
.
keys
(
this
.
cache
).
forEach
(
templateId
=>
{
this
.
cache
[
templateId
].
forEach
(
cachedRow
=>
{
const
renderer
=
this
.
renderers
[
templateId
];
renderer
.
disposeTemplate
(
cachedRow
.
templateData
);
cachedRow
.
element
=
null
;
cachedRow
.
domNode
=
null
;
cachedRow
.
templateData
=
null
;
});
...
...
@@ -112,7 +114,7 @@ export class RowCache<T> implements IDisposable {
}
}
public
dispose
():
void
{
dispose
():
void
{
this
.
garbageCollect
();
this
.
cache
=
null
;
this
.
renderers
=
null
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录