Eliminate allocs - Cache XBounds in Renderer (#1892)

getXBounds creates a disposable XBounds instance on every call.  Cache it and update the values with a set method.  This means XBounds values are now mutable.
This commit is contained in:
Tony Patino 2016-06-29 17:12:47 -07:00
parent d372fd305c
commit a04ad28cec
2 changed files with 19 additions and 4 deletions

View file

@ -58,17 +58,17 @@ public abstract class BarLineScatterCandleBubbleRenderer extends DataRenderer {
/**
* minimum visible entry index
*/
public final int min;
public int min;
/**
* maximum visible entry index
*/
public final int max;
public int max;
/**
* range of visible entry indices
*/
public final int range;
public int range;
/**
* Calculates the minimum and maximum x values as well as the range between them.
@ -77,7 +77,16 @@ public abstract class BarLineScatterCandleBubbleRenderer extends DataRenderer {
* @param dataSet
*/
public XBounds(BarLineScatterCandleBubbleDataProvider chart, IBarLineScatterCandleBubbleDataSet dataSet) {
this.set(chart, dataSet);
}
/**
* Calculates the minimum and maximum x values as well as the range between them.
*
* @param chart
* @param dataSet
*/
public void set(BarLineScatterCandleBubbleDataProvider chart, IBarLineScatterCandleBubbleDataSet dataSet){
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float low = chart.getLowestVisibleX();

View file

@ -302,6 +302,7 @@ public class LineChartRenderer extends LineRadarRenderer {
}
private float[] mLineBuffer = new float[4];
private XBounds xBoundsBuffer;
/**
* Draws a normal line.
@ -331,7 +332,12 @@ public class LineChartRenderer extends LineRadarRenderer {
canvas = c;
}
XBounds bounds = getXBounds(mChart, dataSet);
if(xBoundsBuffer == null){
xBoundsBuffer = getXBounds(mChart, dataSet);
}else{
xBoundsBuffer.set(mChart, dataSet);
}
final XBounds bounds = xBoundsBuffer;
// more than 1 color
if (dataSet.getColors().size() > 1) {