优化性能,降低GC

This commit is contained in:
monitor1394
2019-07-23 21:43:01 +08:00
parent d0b51d9297
commit cb6d0765ca
12 changed files with 276 additions and 161 deletions

View File

@@ -202,15 +202,21 @@ namespace XCharts
return coordinateWidth / (m_BoundaryGap ? dataCount : dataCount - 1);
}
private Dictionary<float, string> _cacheValue2str = new Dictionary<float, string>();
public string GetLabelName(int index, float minValue, float maxValue, DataZoom dataZoom)
{
if (m_Type == AxisType.Value)
{
float value = (minValue + (maxValue - minValue) * index / (GetSplitNumber(dataZoom) - 1));
if (value - (int)value == 0)
return (value).ToString();
if (_cacheValue2str.ContainsKey(value)) return _cacheValue2str[value];
else
return (value).ToString("f1");
{
if (value - (int)value == 0)
_cacheValue2str[value] = (value).ToString();
else
_cacheValue2str[value] = (value).ToString("f1");
return _cacheValue2str[value];
}
}
var showData = GetDataList(dataZoom);
int dataCount = showData.Count;