Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
d223353a
R
runtime
项目概览
dotNET Platform
/
runtime
11 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d223353a
编写于
3月 20, 2022
作者:
S
Stephen Toub
提交者:
GitHub
3月 20, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace XmlSchema ContentValidator Hashtables that are boxing lots of ints (#66908)
上级
c3fa7655
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
73 deletion
+48
-73
src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs
...tem.Private.Xml/src/System/Xml/Schema/ContentValidator.cs
+48
-73
未找到文件。
src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs
浏览文件 @
d223353a
...
...
@@ -39,15 +39,15 @@ public UpaException(object? particle1, object? particle2)
internal
sealed
class
SymbolsDictionary
{
private
int
_last
;
private
readonly
Hashtable
_names
;
private
Hashtable
?
_wildcards
;
private
readonly
Dictionary
<
XmlQualifiedName
,
int
>
_names
;
private
Dictionary
<
string
,
int
>
?
_wildcards
;
private
readonly
ArrayList
_particles
;
private
object
?
_particleLast
;
private
bool
_isUpaEnforced
=
true
;
public
SymbolsDictionary
()
{
_names
=
new
Hashtable
();
_names
=
new
Dictionary
<
XmlQualifiedName
,
int
>
();
_particles
=
new
ArrayList
();
}
...
...
@@ -71,10 +71,8 @@ public bool IsUpaEnforced
/// </summary>
public
int
AddName
(
XmlQualifiedName
name
,
object
?
particle
)
{
object
?
lookup
=
_names
[
name
];
if
(
lookup
!=
null
)
if
(
_names
.
TryGetValue
(
name
,
out
int
symbol
))
{
int
symbol
=
(
int
)
lookup
;
if
(
_particles
[
symbol
]
!=
particle
)
{
_isUpaEnforced
=
false
;
...
...
@@ -116,13 +114,9 @@ public void AddNamespaceList(NamespaceList list, object particle, bool allowLoca
private
void
AddWildcard
(
string
wildcard
,
object
?
particle
)
{
if
(
_wildcards
==
null
)
{
_wildcards
=
new
Hashtable
();
}
_wildcards
??=
new
Dictionary
<
string
,
int
>();
object
?
lookup
=
_wildcards
[
wildcard
];
if
(
lookup
==
null
)
if
(!
_wildcards
.
TryGetValue
(
wildcard
,
out
int
lookup
))
{
_wildcards
.
Add
(
wildcard
,
_last
);
_particles
.
Add
(
particle
);
...
...
@@ -131,15 +125,16 @@ private void AddWildcard(string wildcard, object? particle)
}
else
if
(
particle
!=
null
)
{
_particles
[
(
int
)
lookup
]
=
particle
;
_particles
[
lookup
]
=
particle
;
}
}
public
ICollection
GetNamespaceListSymbols
(
NamespaceList
list
)
{
ArrayList
match
=
new
ArrayList
();
foreach
(
XmlQualifiedName
?
name
in
_names
.
Key
s
)
foreach
(
KeyValuePair
<
XmlQualifiedName
,
int
>
entry
in
_name
s
)
{
XmlQualifiedName
name
=
entry
.
Key
;
Debug
.
Assert
(
name
!=
null
);
if
(
name
!=
XmlQualifiedName
.
Empty
&&
list
.
Allows
(
name
))
{
...
...
@@ -149,11 +144,11 @@ public ICollection GetNamespaceListSymbols(NamespaceList list)
if
(
_wildcards
!=
null
)
{
foreach
(
string
wildcard
in
_wildcards
.
Key
s
)
foreach
(
KeyValuePair
<
string
,
int
>
wildcard
in
_wildcard
s
)
{
if
(
list
.
Allows
(
wildcard
))
if
(
list
.
Allows
(
wildcard
.
Key
))
{
match
.
Add
(
_wildcards
[
wildcard
]
);
match
.
Add
(
wildcard
.
Value
);
}
}
}
...
...
@@ -173,19 +168,14 @@ public ICollection GetNamespaceListSymbols(NamespaceList list)
{
get
{
object
?
lookup
=
_names
[
name
];
if
(
lookup
!=
null
)
if
(
_names
.
TryGetValue
(
name
,
out
int
symbol
))
{
return
(
int
)
lookup
;
return
symbol
;
}
if
(
_wildcards
!=
null
)
if
(
_wildcards
!=
null
&&
_wildcards
.
TryGetValue
(
name
.
Namespace
,
out
int
lookup
)
)
{
lookup
=
_wildcards
[
name
.
Namespace
];
if
(
lookup
!=
null
)
{
return
(
int
)
lookup
;
}
return
lookup
;
}
return
_last
;
// true wildcard
...
...
@@ -195,16 +185,7 @@ public ICollection GetNamespaceListSymbols(NamespaceList list)
/// <summary>
/// Check if a name exists in the symbol dictionary
/// </summary>
public
bool
Exists
(
XmlQualifiedName
name
)
{
object
?
lookup
=
_names
[
name
];
if
(
lookup
!=
null
)
{
return
true
;
}
return
false
;
}
public
bool
Exists
(
XmlQualifiedName
name
)
=>
_names
.
ContainsKey
(
name
);
/// <summary>
/// Return content processing mode for the symbol
...
...
@@ -219,21 +200,21 @@ public bool Exists(XmlQualifiedName name)
/// </summary>
public
string
NameOf
(
int
symbol
)
{
foreach
(
DictionaryEntry
d
e
in
_names
)
foreach
(
KeyValuePair
<
XmlQualifiedName
,
int
>
nam
e
in
_names
)
{
if
(
(
int
)
de
.
Value
!
==
symbol
)
if
(
name
.
Value
==
symbol
)
{
return
((
XmlQualifiedName
)
de
.
Key
)
.
ToString
();
return
name
.
Key
.
ToString
();
}
}
if
(
_wildcards
!=
null
)
{
foreach
(
DictionaryEntry
de
in
_wildcards
)
foreach
(
KeyValuePair
<
string
,
int
>
wildcard
in
_wildcards
)
{
if
(
(
int
)
de
!.
Value
!
==
symbol
)
if
(
wildcard
.
Value
==
symbol
)
{
return
$"
{
(
string
)
de
.
Key
}
:*"
;
return
$"
{
wildcard
.
Key
}
:*"
;
}
}
}
...
...
@@ -1467,7 +1448,7 @@ private void CheckUniqueParticleAttribution(BitSet curpos)
ArrayList
transitionTable
=
new
ArrayList
();
// state lookup table (Dstate in the book)
Hashtable
stateTable
=
new
Hashtable
();
Dictionary
<
BitSet
,
int
>
stateTable
=
new
();
// Add empty set that would signal an error
stateTable
.
Add
(
new
BitSet
(
positionsCount
),
-
1
);
...
...
@@ -1485,7 +1466,7 @@ private void CheckUniqueParticleAttribution(BitSet curpos)
while
(
unmarked
.
Count
>
0
)
{
BitSet
statePosSet
=
unmarked
.
Dequeue
();
// all positions that constitute DFA state
Debug
.
Assert
(
state
==
(
int
)
stateTable
[
statePosSet
]!
);
// just make sure that statePosSet is for correct state
Debug
.
Assert
(
state
==
stateTable
[
statePosSet
]
);
// just make sure that statePosSet is for correct state
int
[]
transition
=
(
int
[])
transitionTable
[
state
]!;
if
(
statePosSet
[
endMarkerPos
])
{
...
...
@@ -1509,10 +1490,9 @@ private void CheckUniqueParticleAttribution(BitSet curpos)
// if U is not empty and is not in Dstates then
// add U as an unmarked state to Dstates
object
?
lookup
=
stateTable
[
newset
];
if
(
lookup
!=
null
)
if
(
stateTable
.
TryGetValue
(
newset
,
out
int
lookup
))
{
transition
[
symbol
]
=
(
int
)
lookup
;
transition
[
symbol
]
=
lookup
;
}
else
{
...
...
@@ -2151,33 +2131,33 @@ public override ArrayList ExpectedParticles(ValidationState context, bool isRequ
internal
sealed
class
AllElementsContentValidator
:
ContentValidator
{
private
readonly
Hashtable
_elements
;
// unique terminal names to positions in Bitset mapping
private
readonly
Dictionary
<
XmlQualifiedName
,
int
>
_elements
;
// unique terminal names to positions in Bitset mapping
private
readonly
object
[]
_particles
;
private
readonly
BitSet
_isRequired
;
// required flags
private
int
_countRequired
;
public
AllElementsContentValidator
(
XmlSchemaContentType
contentType
,
int
size
,
bool
isEmptiable
)
:
base
(
contentType
,
false
,
isEmptiable
)
{
_elements
=
new
Hashtable
(
size
);
_elements
=
new
Dictionary
<
XmlQualifiedName
,
int
>
(
size
);
_particles
=
new
object
[
size
];
_isRequired
=
new
BitSet
(
size
);
}
public
bool
AddElement
(
XmlQualifiedName
name
,
object
particle
,
bool
isEmptiable
)
{
if
(
_elements
[
name
]
!=
null
)
{
return
false
;
}
int
i
=
_elements
.
Count
;
_elements
.
Add
(
name
,
i
);
_particles
[
i
]
=
particle
;
if
(!
isEmptiable
)
if
(
_elements
.
TryAdd
(
name
,
i
))
{
_isRequired
.
Set
(
i
);
_countRequired
++;
_particles
[
i
]
=
particle
;
if
(!
isEmptiable
)
{
_isRequired
.
Set
(
i
);
_countRequired
++;
}
return
true
;
}
return
true
;
return
false
;
}
public
override
bool
IsEmptiable
...
...
@@ -2194,15 +2174,14 @@ public override void InitValidation(ValidationState context)
public
override
object
?
ValidateElement
(
XmlQualifiedName
name
,
ValidationState
context
,
out
int
errorCode
)
{
object
?
lookup
=
_elements
[
name
];
errorCode
=
0
;
if
(
lookup
==
null
)
if
(!
_elements
.
TryGetValue
(
name
,
out
int
index
))
{
context
.
NeedValidateChildren
=
false
;
return
null
;
}
int
index
=
(
int
)
lookup
;
if
(
context
.
AllElementsSet
![
index
])
{
errorCode
=
-
2
;
...
...
@@ -2236,16 +2215,12 @@ public override bool CompleteValidation(ValidationState context)
public
override
ArrayList
?
ExpectedElements
(
ValidationState
context
,
bool
isRequiredOnly
)
{
ArrayList
?
names
=
null
;
foreach
(
DictionaryEntry
entry
in
_elements
)
foreach
(
KeyValuePair
<
XmlQualifiedName
,
int
>
element
in
_elements
)
{
if
(!
context
.
AllElementsSet
![
(
int
)
entry
.
Value
!]
&&
(!
isRequiredOnly
||
_isRequired
[(
int
)
entry
.
Value
]))
if
(!
context
.
AllElementsSet
![
element
.
Value
]
&&
(!
isRequiredOnly
||
_isRequired
[
element
.
Value
]))
{
if
(
names
==
null
)
{
names
=
new
ArrayList
();
}
names
.
Add
(
entry
.
Key
);
names
??=
new
ArrayList
();
names
.
Add
(
element
.
Key
);
}
}
...
...
@@ -2255,11 +2230,11 @@ public override bool CompleteValidation(ValidationState context)
public
override
ArrayList
ExpectedParticles
(
ValidationState
context
,
bool
isRequiredOnly
,
XmlSchemaSet
schemaSet
)
{
ArrayList
expectedParticles
=
new
ArrayList
();
foreach
(
DictionaryEntry
entry
in
_elements
)
foreach
(
KeyValuePair
<
XmlQualifiedName
,
int
>
element
in
_elements
)
{
if
(!
context
.
AllElementsSet
![
(
int
)
entry
.
Value
!]
&&
(!
isRequiredOnly
||
_isRequired
[(
int
)
entry
.
Value
]))
if
(!
context
.
AllElementsSet
![
element
.
Value
]
&&
(!
isRequiredOnly
||
_isRequired
[
element
.
Value
]))
{
AddParticleToExpected
((
_particles
[
(
int
)
entry
.
Value
]
as
XmlSchemaParticle
)!,
schemaSet
,
expectedParticles
);
AddParticleToExpected
((
_particles
[
element
.
Value
]
as
XmlSchemaParticle
)!,
schemaSet
,
expectedParticles
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录