Skip to content

Commit e38487e

Browse files
committed
perf(web): 字典初始化使用源字典容量避免扩容
Dictionary 创建时传入源字典 Count 作为初始容量, 避免 foreach 拷贝过程中触发多次 Resize。 GameFrameX/com.gameframex.unity#5
1 parent b8f9830 commit e38487e

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

Runtime/Web/WebManager.WebBinaryData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static WebBinaryData Create(string url, Dictionary<string, string> header
4949
{
5050
if (data.m_Header == null)
5151
{
52-
data.m_Header = new Dictionary<string, string>();
52+
data.m_Header = new Dictionary<string, string>(header.Count);
5353
}
5454
else
5555
{

Runtime/Web/WebManager.WebJsonData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private static void CopyHeader(WebJsonData data, Dictionary<string, string> head
133133

134134
if (data.m_Header == null)
135135
{
136-
data.m_Header = new Dictionary<string, string>();
136+
data.m_Header = new Dictionary<string, string>(header.Count);
137137
}
138138
else
139139
{
@@ -155,7 +155,7 @@ private static void CopyForm(WebJsonData data, Dictionary<string, object> form)
155155

156156
if (data.m_Form == null)
157157
{
158-
data.m_Form = new Dictionary<string, object>();
158+
data.m_Form = new Dictionary<string, object>(form.Count);
159159
}
160160
else
161161
{

0 commit comments

Comments
 (0)