Java optimization and formatting fixes (#4857)

This commit is contained in:
Sriman Achanta
2022-12-26 14:37:53 -05:00
committed by GitHub
parent 92149efa11
commit 26bdbf3d41
13 changed files with 21 additions and 35 deletions

View File

@@ -4,6 +4,8 @@
package edu.wpi.first.util;
import java.util.Arrays;
/** This is a simple circular buffer so we don't need to "bucket brigade" copy old values. */
public class CircularBuffer {
private double[] m_data;
@@ -21,9 +23,7 @@ public class CircularBuffer {
*/
public CircularBuffer(int size) {
m_data = new double[size];
for (int i = 0; i < m_data.length; i++) {
m_data[i] = 0.0;
}
Arrays.fill(m_data, 0.0);
}
/**
@@ -150,9 +150,7 @@ public class CircularBuffer {
/** Sets internal buffer contents to zero. */
public void clear() {
for (int i = 0; i < m_data.length; i++) {
m_data[i] = 0.0;
}
Arrays.fill(m_data, 0.0);
m_front = 0;
m_length = 0;
}

View File

@@ -34,7 +34,7 @@ public class EventVector {
public void remove(int handle) {
m_lock.lock();
try {
m_events.removeIf(x -> x.intValue() == handle);
m_events.removeIf(x -> x == handle);
} finally {
m_lock.unlock();
}

View File

@@ -92,7 +92,7 @@ public final class RuntimeLoader<T> {
if (hashIs == null) {
throw new IOException(getLoadErrorMessage(ule));
}
try (Scanner scanner = new Scanner(hashIs, StandardCharsets.UTF_8.name())) {
try (Scanner scanner = new Scanner(hashIs, StandardCharsets.UTF_8)) {
String hash = scanner.nextLine();
File jniLibrary = new File(m_extractionRoot, resName + "." + hash);
try {

View File

@@ -9,7 +9,6 @@ import java.io.RandomAccessFile;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.util.NoSuchElementException;
@@ -36,8 +35,7 @@ public class DataLogReader implements Iterable<DataLogRecord> {
public DataLogReader(String filename) throws IOException {
RandomAccessFile f = new RandomAccessFile(filename, "r");
FileChannel channel = f.getChannel();
MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
m_buf = buf;
m_buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
m_buf.order(ByteOrder.LITTLE_ENDIAN);
channel.close();
f.close();