mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 00:57:31 -05:00
Performance improvements (#746)
* Misc minor performance improvements * Use more concise loop syntax * Use more concise Collection sort syntax * Use StringUtils pad methods * Optimize some loops and double-map-lookups * Optimize array instantiation There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]). In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation. * Cleanup string concatenation * Use EnumMap where possible * Use FastMath instead of Math * Initialize complex things only once * Reduce method size to aloow more JIT inlining * remove map of short->float * Move field to local variable * Cleanup Map lookup Co-authored-by: Rob Ekl <xwq876@zebra.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.dsp.fsk;
|
||||
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class SampleBuffer
|
||||
mIntegerSamplesPerSymbol = (int)(samplesPerSymbol + 0.5f);
|
||||
mHalfIntegerSamplesPerSymbol = (int)(samplesPerSymbol / 2.0f + 0.5f);
|
||||
mMidSymbolSamplingPoint = samplesPerSymbol + mHalfIntegerSamplesPerSymbol;
|
||||
mTwiceSamplesPerSymbol = (int)Math.floor(2.0 * samplesPerSymbol);
|
||||
mTwiceSamplesPerSymbol = (int) FastMath.floor(2.0 * samplesPerSymbol);
|
||||
mDelayLine = new boolean[2 * mTwiceSamplesPerSymbol];
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.dsp.fsk;
|
||||
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
/**
|
||||
* Zero crossing error detector. Provides symbol timing error correction values by detecting zero-crossings within
|
||||
* each symbol period. Ideally there should be only 0 or 1 zero crossings within each symbol period. However, when
|
||||
@@ -45,7 +47,7 @@ public class ZeroCrossingErrorDetector
|
||||
*/
|
||||
public ZeroCrossingErrorDetector(float samplesPerSymbol)
|
||||
{
|
||||
mBuffer = new boolean[(int)Math.ceil(samplesPerSymbol)];
|
||||
mBuffer = new boolean[(int)FastMath.ceil(samplesPerSymbol)];
|
||||
// mZeroCrossingIdeal = mBuffer.length - 1.5f - (samplesPerSymbol / 2.0f); //Preserve this for LTR
|
||||
mZeroCrossingIdeal = (samplesPerSymbol / 2.0f);
|
||||
}
|
||||
@@ -108,7 +110,7 @@ public class ZeroCrossingErrorDetector
|
||||
float errorDistanceOne = mZeroCrossingIdeal - mZeroCrossingOne;
|
||||
float errorDistanceTwo = mZeroCrossingCount - mZeroCrossingTwo;
|
||||
|
||||
if(Math.abs(errorDistanceOne) < Math.abs(errorDistanceTwo))
|
||||
if(FastMath.abs(errorDistanceOne) < FastMath.abs(errorDistanceTwo))
|
||||
{
|
||||
mDetectedZeroCrossing = mZeroCrossingOne;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user