forked from JanKallman/EPPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote handling om exceladdresses in functions. Introduced a cache f…
…or addresses, available via ParsingContext. ExcelRanges are now always compiled in ExcelAddressExpression, the SkipArgumentEvaluation parameter is removed, and addresses can be accessed via cache references
- Loading branch information
Showing
30 changed files
with
344 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace EPPlus.FormulaParsing | ||
{ | ||
/// <summary> | ||
/// Caches string by generated id's. | ||
/// </summary> | ||
public class ExcelAddressCache | ||
{ | ||
private readonly object _myLock = new object(); | ||
private readonly Dictionary<int, string> _addressCache = new Dictionary<int, string>(); | ||
private readonly Dictionary<string, int> _lookupCache = new Dictionary<string, int>(); | ||
private int _nextId = 1; | ||
private const bool EnableLookupCache = false; | ||
|
||
/// <summary> | ||
/// Returns an id to use for caching (when the <see cref="Add"/> method is called) | ||
/// </summary> | ||
/// <returns></returns> | ||
public int GetNewId() | ||
{ | ||
lock(_myLock) | ||
{ | ||
return _nextId++; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Adds an address to the cache | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <param name="address"></param> | ||
/// <returns></returns> | ||
public bool Add(int id, string address) | ||
{ | ||
lock(_myLock) | ||
{ | ||
if (_addressCache.ContainsKey(id)) return false; | ||
_addressCache.Add(id, address); | ||
if(EnableLookupCache && !_lookupCache.ContainsKey(address)) | ||
_lookupCache.Add(address, id); | ||
return true; | ||
} | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Number of items in the cache | ||
/// </summary> | ||
public int Count | ||
{ | ||
get { return _addressCache.Count; } | ||
} | ||
|
||
/// <summary> | ||
/// Returns an address by its cache id | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
public string Get(int id) | ||
{ | ||
if (!_addressCache.ContainsKey(id)) return string.Empty; | ||
return _addressCache[id]; | ||
} | ||
|
||
/// <summary> | ||
/// Clears the cache | ||
/// </summary> | ||
public void Clear() | ||
{ | ||
lock(_myLock) | ||
{ | ||
_addressCache.Clear(); | ||
_lookupCache.Clear(); | ||
_nextId = 1; | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.