Skip to content
This repository was archived by the owner on Mar 9, 2020. It is now read-only.

Speed up ExcelStyleCollection #630

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions EPPlus/ExcelStyleCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*******************************************************************************
/*******************************************************************************
* You may amend and distribute as you like, but don't remove this header!
*
* EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
@@ -94,8 +94,10 @@ public int Count
internal int Add(string key, T item)
{
_list.Add(item);
if (!_dic.ContainsKey(key.ToLower(CultureInfo.InvariantCulture))) _dic.Add(key.ToLower(CultureInfo.InvariantCulture), _list.Count - 1);
if (_setNextIdManual) NextId++;
if (!_dic.ContainsKey(key))
_dic.Add(key, _list.Count - 1);
if (_setNextIdManual)
NextId++;
return _list.Count-1;
}
/// <summary>
@@ -106,9 +108,9 @@ internal int Add(string key, T item)
/// <returns>True if found</returns>
internal bool FindByID(string key, ref T obj)
{
if (_dic.ContainsKey(key))
if (_dic.TryGetValue(key, out int idx))
{
obj = _list[_dic[key.ToLower(CultureInfo.InvariantCulture)]];
obj = _list[idx];
return true;
}
else
@@ -123,9 +125,9 @@ internal bool FindByID(string key, ref T obj)
/// <returns></returns>
internal int FindIndexByID(string key)
{
if (_dic.ContainsKey(key))
if (_dic.TryGetValue(key, out int idx))
{
return _dic[key];
return idx;
}
else
{