Optimization of Bus.isComplete()

This commit is contained in:
Max840 committed 2013-12-26 17:25:52 -05:00
1 parent d8deca227f
commit bc6b93e3fe
1 file changed
+5 -31
+5 -31
View File
@@ -114,40 +114,14 @@ public class Bus {
return false; return false;
} }
// Loop over devices and ensure they are contiguous. // Loop over devices and add their size
MemoryRange prev = null; int filledMemory = 0;
int i = 0;
int length = devices.size();
for (Device d : devices) { for (Device d : devices) {
MemoryRange cur = d.getMemoryRange(); filledMemory += d.getSize();
if (i == 0) {
// If the first entry doesn't start at 'startAddress', return false.
if (cur.startAddress() != startAddress) {
return false;
}
} }
if (prev != null && i < length - 1) { // Returns if the total size of the devices fill the bus' memory space
// Otherwise, compare previous map's end against this map's return filledMemory == endAddress - startAddress + 1;
// endAddress. They must be adjacent!
if (cur.startAddress() - 1 != prev.endAddress()) {
return false;
}
}
if (i == length - 1) {
// If the last entry doesn't end at endAddress, return false;
if (cur.endAddress() != endAddress) {
return false;
}
}
i++;
prev = cur;
}
// Must be complete.
return true;
} }
public int read(int address) throws MemoryAccessException { public int read(int address) throws MemoryAccessException {